| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test suite for netlogon PAC operations |
| 5 |
|
| 6 |
Copyright (C) Andrew Bartlett <[email protected]> 2012 |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 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/cmdline.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" |
| 38 |
#include <ldb.h> |
| 39 |
#include "ldb_wrap.h" |
| 40 |
#include "dsdb/samdb/samdb.h" |
| 41 |
|
| 42 |
#define TEST_MACHINE_NAME_BDC "torturepacbdc" |
| 43 |
#define TEST_MACHINE_NAME_WKSTA "torturepacwksta" |
| 44 |
#define TEST_MACHINE_NAME_S4U2SELF_BDC "tests4u2selfbdc" |
| 45 |
#define TEST_MACHINE_NAME_S4U2SELF_WKSTA "tests4u2selfwk" |
| 46 |
#define TEST_MACHINE_NAME_S4U2PROXY_WKSTA "tests4u2proxywk" |
| 47 |
|
| 48 |
struct pac_data { |
| 49 |
DATA_BLOB pac_blob; |
| 50 |
struct PAC_SIGNATURE_DATA *pac_srv_sig; |
| 51 |
struct PAC_SIGNATURE_DATA *pac_kdc_sig; |
| 52 |
}; |
| 53 |
|
| 54 |
/* A helper function which avoids touching the local databases to |
| 55 |
* generate the session info, as we just want to verify the PAC |
| 56 |
* details, not the full local token */ |
| 57 |
static NTSTATUS test_generate_session_info_pac(struct auth4_context *auth_ctx, |
| 58 |
TALLOC_CTX *mem_ctx, |
| 59 |
struct smb_krb5_context *smb_krb5_context, |
| 60 |
DATA_BLOB *pac_blob, |
| 61 |
const char *principal_name, |
| 62 |
const struct tsocket_address *remote_address, |
| 63 |
uint32_t session_info_flags, |
| 64 |
struct auth_session_info **session_info) |
| 65 |
{ |
| 66 |
NTSTATUS nt_status; |
| 67 |
struct auth_user_info_dc *user_info_dc; |
| 68 |
TALLOC_CTX *tmp_ctx; |
| 69 |
struct pac_data *pac_data; |
| 70 |
|
| 71 |
if (pac_blob == NULL) { |
| 72 |
DBG_ERR("pac_blob missing\n"); |
| 73 |
return NT_STATUS_NO_IMPERSONATION_TOKEN; |
| 74 |
} |
| 75 |
|
| 76 |
tmp_ctx = talloc_named(mem_ctx, 0, "gensec_gssapi_session_info context"); |
| 77 |
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx); |
| 78 |
|
| 79 |
auth_ctx->private_data = pac_data = talloc_zero(auth_ctx, struct pac_data); |
| 80 |
|
| 81 |
pac_data->pac_blob = data_blob_dup_talloc(pac_data, *pac_blob); |
| 82 |
if (pac_data->pac_blob.length != pac_blob->length) { |
| 83 |
talloc_free(tmp_ctx); |
| 84 |
return NT_STATUS_NO_MEMORY; |
| 85 |
} |
| 86 |
|
| 87 |
pac_data->pac_srv_sig = talloc(tmp_ctx, struct PAC_SIGNATURE_DATA); |
| 88 |
if (!pac_data->pac_srv_sig) { |
| 89 |
talloc_free(tmp_ctx); |
| 90 |
return NT_STATUS_NO_MEMORY; |
| 91 |
} |
| 92 |
pac_data->pac_kdc_sig = talloc(tmp_ctx, struct PAC_SIGNATURE_DATA); |
| 93 |
if (!pac_data->pac_kdc_sig) { |
| 94 |
talloc_free(tmp_ctx); |
| 95 |
return NT_STATUS_NO_MEMORY; |
| 96 |
} |
| 97 |
|
| 98 |
nt_status = kerberos_pac_blob_to_user_info_dc(tmp_ctx, |
| 99 |
*pac_blob, |
| 100 |
smb_krb5_context->krb5_context, |
| 101 |
&user_info_dc, |
| 102 |
pac_data->pac_srv_sig, |
| 103 |
pac_data->pac_kdc_sig); |
| 104 |
if (!NT_STATUS_IS_OK(nt_status)) { |
| 105 |
talloc_free(tmp_ctx); |
| 106 |
return nt_status; |
| 107 |
} |
| 108 |
|
| 109 |
talloc_steal(pac_data, pac_data->pac_srv_sig); |
| 110 |
talloc_steal(pac_data, pac_data->pac_kdc_sig); |
| 111 |
|
| 112 |
if (!(user_info_dc->info->user_flags & NETLOGON_GUEST)) { |
| 113 |
session_info_flags |= AUTH_SESSION_INFO_AUTHENTICATED; |
| 114 |
} |
| 115 |
|
| 116 |
session_info_flags |= AUTH_SESSION_INFO_SIMPLE_PRIVILEGES; |
| 117 |
nt_status = auth_generate_session_info(mem_ctx, |
| 118 |
NULL, |
| 119 |
NULL, |
| 120 |
user_info_dc, session_info_flags, |
| 121 |
session_info); |
| 122 |
if (!NT_STATUS_IS_OK(nt_status)) { |
| 123 |
talloc_free(tmp_ctx); |
| 124 |
return nt_status; |
| 125 |
} |
| 126 |
|
| 127 |
talloc_free(tmp_ctx); |
| 128 |
return nt_status; |
| 129 |
} |
| 130 |
|
| 131 |
/* Check to see if we can pass the PAC across to the NETLOGON server for validation */ |
| 132 |
|
| 133 |
static const struct PAC_BUFFER *get_pac_buffer(const struct PAC_DATA *pac_data, |
| 134 |
enum PAC_TYPE type) |
| 135 |
{ |
| 136 |
const struct PAC_BUFFER *pac_buf = NULL; |
| 137 |
uint32_t i; |
| 138 |
|
| 139 |
for (i = 0; i < pac_data->num_buffers; ++i) { |
| 140 |
pac_buf = &pac_data->buffers[i]; |
| 141 |
|
| 142 |
if (pac_buf->type == type) { |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
return pac_buf; |
| 148 |
} |
| 149 |
|
| 150 |
/* Also happens to be a really good one-step verification of our Kerberos stack */ |
| 151 |
|
| 152 |
static bool netlogon_validate_pac(struct torture_context *tctx, |
| 153 |
struct dcerpc_pipe *p1, |
| 154 |
struct cli_credentials *server_creds, |
| 155 |
enum netr_SchannelType secure_channel_type, |
| 156 |
const char *test_machine_name, |
| 157 |
uint32_t negotiate_flags, |
| 158 |
struct pac_data *pac_data, |
| 159 |
struct auth_session_info *session_info); |
| 160 |
|
| 161 |
static bool test_PACVerify(struct torture_context *tctx, |
| 162 |
struct dcerpc_pipe *p, |
| 163 |
struct cli_credentials *credentials, |
| 164 |
enum netr_SchannelType secure_channel_type, |
| 165 |
const char *test_machine_name, |
| 166 |
uint32_t negotiate_flags) |
| 167 |
{ |
| 168 |
NTSTATUS status; |
| 169 |
bool ok; |
| 170 |
const char *pkinit_ccache = torture_setting_string(tctx, "pkinit_ccache", NULL); |
| 171 |
bool pkinit_in_use = pkinit_ccache != NULL; |
| 172 |
bool expect_pac_upn_dns_info = torture_setting_bool(tctx, "expect_pac_upn_dns_info", true); |
| 173 |
size_t num_pac_buffers; |
| 174 |
struct gensec_security *gensec_client_context; |
| 175 |
struct gensec_security *gensec_server_context; |
| 176 |
struct cli_credentials *client_creds; |
| 177 |
struct cli_credentials *server_creds; |
| 178 |
|
| 179 |
DATA_BLOB client_to_server, server_to_client; |
| 180 |
struct PAC_DATA pac_data_struct; |
| 181 |
enum ndr_err_code ndr_err; |
| 182 |
|
| 183 |
struct auth4_context *auth_context; |
| 184 |
struct auth_session_info *session_info; |
| 185 |
struct pac_data *pac_data; |
| 186 |
const struct PAC_BUFFER *pac_buf = NULL; |
| 187 |
|
| 188 |
TALLOC_CTX *tmp_ctx = talloc_new(tctx); |
| 189 |
torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed"); |
| 190 |
|
| 191 |
torture_comment(tctx, |
| 192 |
"Testing PAC Verify (secure_channel_type: %d, machine: %s, negotiate_flags: 0x%08x\n", |
| 193 |
secure_channel_type, test_machine_name, negotiate_flags); |
| 194 |
|
| 195 |
if (pkinit_in_use) { |
| 196 |
struct cli_credentials *tmp_creds = NULL; |
| 197 |
const char *error_string = NULL; |
| 198 |
int rc; |
| 199 |
|
| 200 |
torture_comment(tctx, |
| 201 |
"Using pkinit_ccache=%s\n", |
| 202 |
pkinit_ccache); |
| 203 |
|
| 204 |
tmp_creds = cli_credentials_init(tctx); |
| 205 |
torture_assert(tctx, tmp_creds, "Failed to create credentials"); |
| 206 |
|
| 207 |
rc = cli_credentials_set_ccache(tmp_creds, |
| 208 |
tctx->lp_ctx, |
| 209 |
pkinit_ccache, |
| 210 |
CRED_SPECIFIED, |
| 211 |
&error_string); |
| 212 |
torture_assert_int_equal(tctx, |
| 213 |
rc, |
| 214 |
0, |
| 215 |
"cli_credentials_set_ccache failed"); |
| 216 |
cli_credentials_set_kerberos_state(tmp_creds, |
| 217 |
CRED_USE_KERBEROS_REQUIRED, |
| 218 |
CRED_SPECIFIED); |
| 219 |
|
| 220 |
/* |
| 221 |
* Copy the credentials in order to use a different MEMORY krb5 |
| 222 |
* ccache for each client/server setup. The MEMORY cache |
| 223 |
* identifier is a pointer to the creds container. If we copy |
| 224 |
* it the pointer changes and we will get a new clean memory |
| 225 |
* cache. |
| 226 |
*/ |
| 227 |
client_creds = |
| 228 |
cli_credentials_shallow_copy(tmp_ctx, tmp_creds); |
| 229 |
torture_assert(tctx, |
| 230 |
client_creds, |
| 231 |
"Failed to copy of credentials"); |
| 232 |
} else { |
| 233 |
/* |
| 234 |
* Copy the credentials in order to use a different MEMORY krb5 |
| 235 |
* ccache for each client/server setup. The MEMORY cache |
| 236 |
* identifier is a pointer to the creds container. If we copy |
| 237 |
* it the pointer changes and we will get a new clean memory |
| 238 |
* cache. |
| 239 |
*/ |
| 240 |
client_creds = |
| 241 |
cli_credentials_shallow_copy(tmp_ctx, |
| 242 |
samba_cmdline_get_creds()); |
| 243 |
torture_assert(tctx, |
| 244 |
client_creds, |
| 245 |
"Failed to copy of credentials"); |
| 246 |
cli_credentials_invalidate_ccache(client_creds, CRED_SPECIFIED); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
server_creds = cli_credentials_shallow_copy(tmp_ctx, |
| 251 |
credentials); |
| 252 |
torture_assert(tctx, server_creds, "Failed to copy of credentials"); |
| 253 |
|
| 254 |
auth_context = talloc_zero(tmp_ctx, struct auth4_context); |
| 255 |
torture_assert(tctx, auth_context != NULL, "talloc_new() failed"); |
| 256 |
|
| 257 |
auth_context->generate_session_info_pac = test_generate_session_info_pac; |
| 258 |
|
| 259 |
status = gensec_client_start(tctx, &gensec_client_context, |
| 260 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 261 |
torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed"); |
| 262 |
|
| 263 |
status = gensec_set_target_hostname(gensec_client_context, test_machine_name); |
| 264 |
|
| 265 |
status = gensec_set_credentials(gensec_client_context, client_creds); |
| 266 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed"); |
| 267 |
|
| 268 |
status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI"); |
| 269 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed"); |
| 270 |
|
| 271 |
status = gensec_server_start(tctx, |
| 272 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx), |
| 273 |
auth_context, &gensec_server_context); |
| 274 |
torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed"); |
| 275 |
|
| 276 |
status = gensec_set_credentials(gensec_server_context, server_creds); |
| 277 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed"); |
| 278 |
|
| 279 |
status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI"); |
| 280 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed"); |
| 281 |
|
| 282 |
server_to_client = data_blob(NULL, 0); |
| 283 |
|
| 284 |
do { |
| 285 |
/* Do a client-server update dance */ |
| 286 |
status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server); |
| 287 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 288 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed"); |
| 289 |
} |
| 290 |
|
| 291 |
status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client); |
| 292 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 293 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed"); |
| 294 |
} |
| 295 |
|
| 296 |
if (NT_STATUS_IS_OK(status)) { |
| 297 |
break; |
| 298 |
} |
| 299 |
} while (1); |
| 300 |
|
| 301 |
/* Extract the PAC using Samba's code */ |
| 302 |
|
| 303 |
status = gensec_session_info(gensec_server_context, gensec_server_context, &session_info); |
| 304 |
torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed"); |
| 305 |
|
| 306 |
pac_data = talloc_get_type(auth_context->private_data, struct pac_data); |
| 307 |
|
| 308 |
torture_assert(tctx, pac_data != NULL, "gensec_update failed to fill in pac_data in auth_context"); |
| 309 |
torture_assert(tctx, pac_data->pac_srv_sig != NULL, "pac_srv_sig not present"); |
| 310 |
torture_assert(tctx, pac_data->pac_kdc_sig != NULL, "pac_kdc_sig not present"); |
| 311 |
|
| 312 |
ndr_err = ndr_pull_struct_blob(&pac_data->pac_blob, tmp_ctx, &pac_data_struct, |
| 313 |
(ndr_pull_flags_fn_t)ndr_pull_PAC_DATA); |
| 314 |
torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_pull_struct_blob of PAC_DATA structure failed"); |
| 315 |
|
| 316 |
num_pac_buffers = 7; |
| 317 |
if (expect_pac_upn_dns_info) { |
| 318 |
num_pac_buffers += 1; |
| 319 |
} |
| 320 |
if (pkinit_in_use) { |
| 321 |
num_pac_buffers += 1; |
| 322 |
} |
| 323 |
|
| 324 |
torture_assert_int_equal(tctx, pac_data_struct.version, 0, "version"); |
| 325 |
torture_assert_int_equal(tctx, pac_data_struct.num_buffers, num_pac_buffers, "num_buffers"); |
| 326 |
|
| 327 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_LOGON_INFO); |
| 328 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_LOGON_INFO"); |
| 329 |
torture_assert(tctx, |
| 330 |
pac_buf->info != NULL, |
| 331 |
"PAC_TYPE_LOGON_INFO info"); |
| 332 |
|
| 333 |
if (pkinit_in_use) { |
| 334 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_CREDENTIAL_INFO); |
| 335 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_CREDENTIAL_INFO"); |
| 336 |
torture_assert(tctx, |
| 337 |
pac_buf->info != NULL, |
| 338 |
"PAC_TYPE_CREDENTIAL_INFO info"); |
| 339 |
} |
| 340 |
|
| 341 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_LOGON_NAME); |
| 342 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_LOGON_NAME"); |
| 343 |
torture_assert(tctx, |
| 344 |
pac_buf->info != NULL, |
| 345 |
"PAC_TYPE_LOGON_NAME info"); |
| 346 |
|
| 347 |
if (expect_pac_upn_dns_info) { |
| 348 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_UPN_DNS_INFO); |
| 349 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_UPN_DNS_INFO"); |
| 350 |
torture_assert(tctx, |
| 351 |
pac_buf->info != NULL, |
| 352 |
"PAC_TYPE_UPN_DNS_INFO info"); |
| 353 |
} |
| 354 |
|
| 355 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_SRV_CHECKSUM); |
| 356 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_SRV_CHECKSUM"); |
| 357 |
torture_assert(tctx, |
| 358 |
pac_buf->info != NULL, |
| 359 |
"PAC_TYPE_SRV_CHECKSUM info"); |
| 360 |
|
| 361 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_KDC_CHECKSUM); |
| 362 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_KDC_CHECKSUM"); |
| 363 |
torture_assert(tctx, |
| 364 |
pac_buf->info != NULL, |
| 365 |
"PAC_TYPE_KDC_CHECKSUM info"); |
| 366 |
|
| 367 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_TICKET_CHECKSUM); |
| 368 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_TICKET_CHECKSUM"); |
| 369 |
torture_assert(tctx, |
| 370 |
pac_buf->info != NULL, |
| 371 |
"PAC_TYPE_TICKET_CHECKSUM info"); |
| 372 |
|
| 373 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_FULL_CHECKSUM); |
| 374 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_FULL_CHECKSUM"); |
| 375 |
torture_assert(tctx, |
| 376 |
pac_buf->info != NULL, |
| 377 |
"PAC_TYPE_FULL_CHECKSUM info"); |
| 378 |
|
| 379 |
ok = netlogon_validate_pac(tctx, p, server_creds, secure_channel_type, test_machine_name, |
| 380 |
negotiate_flags, pac_data, session_info); |
| 381 |
|
| 382 |
talloc_free(tmp_ctx); |
| 383 |
|
| 384 |
return ok; |
| 385 |
} |
| 386 |
|
| 387 |
static bool netlogon_validate_pac(struct torture_context *tctx, |
| 388 |
struct dcerpc_pipe *p1, |
| 389 |
struct cli_credentials *server_creds, |
| 390 |
enum netr_SchannelType secure_channel_type, |
| 391 |
const char *test_machine_name, |
| 392 |
uint32_t negotiate_flags, |
| 393 |
struct pac_data *pac_data, |
| 394 |
struct auth_session_info *session_info) |
| 395 |
{ |
| 396 |
struct PAC_Validate pac_wrapped_struct; |
| 397 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 398 |
struct netr_Authenticator return_authenticator; |
| 399 |
struct netr_Authenticator auth, auth2; |
| 400 |
struct netr_GenericInfo generic; |
| 401 |
struct netr_LogonSamLogon r; |
| 402 |
union netr_Validation validation; |
| 403 |
union netr_LogonLevel logon; |
| 404 |
uint8_t authoritative; |
| 405 |
struct dcerpc_pipe *p = NULL; |
| 406 |
struct dcerpc_binding_handle *b = NULL; |
| 407 |
enum ndr_err_code ndr_err; |
| 408 |
DATA_BLOB payload, pac_wrapped; |
| 409 |
enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE; |
| 410 |
enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE; |
| 411 |
NTSTATUS status; |
| 412 |
|
| 413 |
if (negotiate_flags & NETLOGON_NEG_SUPPORTS_KERBEROS_AUTH) { |
| 414 |
const struct dcerpc_binding *b1 = |
| 415 |
dcerpc_binding_handle_get_binding(p1->binding_handle); |
| 416 |
struct dcerpc_binding *b2 = NULL; |
| 417 |
|
| 418 |
b2 = dcerpc_binding_dup(tctx, b1); |
| 419 |
torture_assert(tctx, b2 != NULL, "dcerpc_binding_dup"); |
| 420 |
dcerpc_binding_set_flags(b2, |
| 421 |
DCERPC_SCHANNEL | DCERPC_SCHANNEL_KRB5, |
| 422 |
DCERPC_AUTH_OPTIONS); |
| 423 |
|
| 424 |
cli_credentials_set_netlogon_creds(server_creds, NULL); |
| 425 |
status = dcerpc_pipe_connect_b(tctx, &p, b2, |
| 426 |
&ndr_table_netlogon, |
| 427 |
server_creds, |
| 428 |
tctx->ev, tctx->lp_ctx); |
| 429 |
torture_assert_ntstatus_ok(tctx, status, |
| 430 |
"dcerpc_pipe_connect_b(DCERPC_SCHANNEL_KRB5)\n"); |
| 431 |
creds = cli_credentials_get_netlogon_creds(server_creds); |
| 432 |
goto connected; |
| 433 |
} |
| 434 |
|
| 435 |
if (!test_SetupCredentials2(p1, tctx, negotiate_flags, |
| 436 |
server_creds, secure_channel_type, |
| 437 |
&creds)) { |
| 438 |
return false; |
| 439 |
} |
| 440 |
if (!test_SetupCredentialsPipe(p1, tctx, server_creds, creds, |
| 441 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 442 |
return false; |
| 443 |
} |
| 444 |
connected: |
| 445 |
b = p->binding_handle; |
| 446 |
|
| 447 |
pac_wrapped_struct.ChecksumLength = pac_data->pac_srv_sig->signature.length; |
| 448 |
pac_wrapped_struct.SignatureType = pac_data->pac_kdc_sig->type; |
| 449 |
pac_wrapped_struct.SignatureLength = pac_data->pac_kdc_sig->signature.length; |
| 450 |
pac_wrapped_struct.ChecksumAndSignature = payload |
| 451 |
= data_blob_talloc(tctx, NULL, |
| 452 |
pac_wrapped_struct.ChecksumLength |
| 453 |
+ pac_wrapped_struct.SignatureLength); |
| 454 |
memcpy(&payload.data[0], |
| 455 |
pac_data->pac_srv_sig->signature.data, |
| 456 |
pac_wrapped_struct.ChecksumLength); |
| 457 |
memcpy(&payload.data[pac_wrapped_struct.ChecksumLength], |
| 458 |
pac_data->pac_kdc_sig->signature.data, |
| 459 |
pac_wrapped_struct.SignatureLength); |
| 460 |
|
| 461 |
ndr_err = ndr_push_struct_blob(&pac_wrapped, tctx, &pac_wrapped_struct, |
| 462 |
(ndr_push_flags_fn_t)ndr_push_PAC_Validate); |
| 463 |
torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed"); |
| 464 |
|
| 465 |
torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption"); |
| 466 |
|
| 467 |
generic.length = pac_wrapped.length; |
| 468 |
generic.data = pac_wrapped.data; |
| 469 |
|
| 470 |
/* Validate it over the netlogon pipe */ |
| 471 |
|
| 472 |
generic.identity_info.parameter_control = 0; |
| 473 |
generic.identity_info.logon_id = 0; |
| 474 |
generic.identity_info.domain_name.string = session_info->info->domain_name; |
| 475 |
generic.identity_info.account_name.string = session_info->info->account_name; |
| 476 |
generic.identity_info.workstation.string = test_machine_name; |
| 477 |
|
| 478 |
generic.package_name.string = "Kerberos"; |
| 479 |
|
| 480 |
logon.generic = &generic; |
| 481 |
|
| 482 |
ZERO_STRUCT(auth2); |
| 483 |
netlogon_creds_client_authenticator(creds, &auth); |
| 484 |
r.in.credential = &auth; |
| 485 |
r.in.return_authenticator = &auth2; |
| 486 |
r.in.logon = &logon; |
| 487 |
r.in.logon_level = NetlogonGenericInformation; |
| 488 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 489 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 490 |
r.in.validation_level = NetlogonValidationGenericInfo2; |
| 491 |
r.out.validation = &validation; |
| 492 |
r.out.authoritative = &authoritative; |
| 493 |
r.out.return_authenticator = &return_authenticator; |
| 494 |
|
| 495 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 496 |
status = netlogon_creds_encrypt_samlogon_logon(creds, |
| 497 |
r.in.logon_level, |
| 498 |
r.in.logon, |
| 499 |
auth_type, |
| 500 |
auth_level); |
| 501 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samlogon_logon"); |
| 502 |
|
| 503 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 504 |
"LogonSamLogon failed"); |
| 505 |
|
| 506 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed"); |
| 507 |
|
| 508 |
/* This will break the signature nicely (even in the crypto wrapping), check we get a logon failure */ |
| 509 |
generic.data[generic.length-1]++; |
| 510 |
|
| 511 |
logon.generic = &generic; |
| 512 |
|
| 513 |
ZERO_STRUCT(auth2); |
| 514 |
netlogon_creds_client_authenticator(creds, &auth); |
| 515 |
r.in.credential = &auth; |
| 516 |
r.in.return_authenticator = &auth2; |
| 517 |
r.in.logon_level = NetlogonGenericInformation; |
| 518 |
r.in.logon = &logon; |
| 519 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 520 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 521 |
r.in.validation_level = NetlogonValidationGenericInfo2; |
| 522 |
|
| 523 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 524 |
"LogonSamLogon failed"); |
| 525 |
|
| 526 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed"); |
| 527 |
|
| 528 |
status = netlogon_creds_client_verify(creds, |
| 529 |
&r.out.return_authenticator->cred, |
| 530 |
auth_type, |
| 531 |
auth_level); |
| 532 |
torture_assert_ntstatus_ok(tctx, status, |
| 533 |
"Credential chaining failed"); |
| 534 |
|
| 535 |
/* This will break the parsing nicely (even in the crypto wrapping), check we get INVALID_PARAMETER */ |
| 536 |
generic.length--; |
| 537 |
|
| 538 |
logon.generic = &generic; |
| 539 |
|
| 540 |
ZERO_STRUCT(auth2); |
| 541 |
netlogon_creds_client_authenticator(creds, &auth); |
| 542 |
r.in.credential = &auth; |
| 543 |
r.in.return_authenticator = &auth2; |
| 544 |
r.in.logon_level = NetlogonGenericInformation; |
| 545 |
r.in.logon = &logon; |
| 546 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 547 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 548 |
r.in.validation_level = NetlogonValidationGenericInfo2; |
| 549 |
|
| 550 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 551 |
"LogonSamLogon failed"); |
| 552 |
|
| 553 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed"); |
| 554 |
|
| 555 |
status = netlogon_creds_client_verify(creds, |
| 556 |
&r.out.return_authenticator->cred, |
| 557 |
auth_type, |
| 558 |
auth_level); |
| 559 |
torture_assert_ntstatus_ok(tctx, status, |
| 560 |
"Credential chaining failed"); |
| 561 |
|
| 562 |
pac_wrapped_struct.ChecksumLength = pac_data->pac_srv_sig->signature.length; |
| 563 |
pac_wrapped_struct.SignatureType = pac_data->pac_kdc_sig->type; |
| 564 |
|
| 565 |
/* Break the SignatureType */ |
| 566 |
pac_wrapped_struct.SignatureType++; |
| 567 |
|
| 568 |
pac_wrapped_struct.SignatureLength = pac_data->pac_kdc_sig->signature.length; |
| 569 |
pac_wrapped_struct.ChecksumAndSignature = payload |
| 570 |
= data_blob_talloc(tctx, NULL, |
| 571 |
pac_wrapped_struct.ChecksumLength |
| 572 |
+ pac_wrapped_struct.SignatureLength); |
| 573 |
memcpy(&payload.data[0], |
| 574 |
pac_data->pac_srv_sig->signature.data, |
| 575 |
pac_wrapped_struct.ChecksumLength); |
| 576 |
memcpy(&payload.data[pac_wrapped_struct.ChecksumLength], |
| 577 |
pac_data->pac_kdc_sig->signature.data, |
| 578 |
pac_wrapped_struct.SignatureLength); |
| 579 |
|
| 580 |
ndr_err = ndr_push_struct_blob(&pac_wrapped, tctx, &pac_wrapped_struct, |
| 581 |
(ndr_push_flags_fn_t)ndr_push_PAC_Validate); |
| 582 |
torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed"); |
| 583 |
|
| 584 |
torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption"); |
| 585 |
|
| 586 |
generic.length = pac_wrapped.length; |
| 587 |
generic.data = pac_wrapped.data; |
| 588 |
|
| 589 |
logon.generic = &generic; |
| 590 |
|
| 591 |
ZERO_STRUCT(auth2); |
| 592 |
netlogon_creds_client_authenticator(creds, &auth); |
| 593 |
r.in.credential = &auth; |
| 594 |
r.in.return_authenticator = &auth2; |
| 595 |
r.in.logon_level = NetlogonGenericInformation; |
| 596 |
r.in.logon = &logon; |
| 597 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 598 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 599 |
r.in.validation_level = NetlogonValidationGenericInfo2; |
| 600 |
|
| 601 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 602 |
status = netlogon_creds_encrypt_samlogon_logon(creds, |
| 603 |
r.in.logon_level, |
| 604 |
r.in.logon, |
| 605 |
auth_type, |
| 606 |
auth_level); |
| 607 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samlogon_logon"); |
| 608 |
|
| 609 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 610 |
"LogonSamLogon failed"); |
| 611 |
|
| 612 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed"); |
| 613 |
|
| 614 |
status = netlogon_creds_client_verify(creds, |
| 615 |
&r.out.return_authenticator->cred, |
| 616 |
auth_type, |
| 617 |
auth_level); |
| 618 |
torture_assert_ntstatus_ok(tctx, status, |
| 619 |
"Credential chaining failed"); |
| 620 |
|
| 621 |
pac_wrapped_struct.ChecksumLength = pac_data->pac_srv_sig->signature.length; |
| 622 |
pac_wrapped_struct.SignatureType = pac_data->pac_kdc_sig->type; |
| 623 |
pac_wrapped_struct.SignatureLength = pac_data->pac_kdc_sig->signature.length; |
| 624 |
|
| 625 |
pac_wrapped_struct.ChecksumAndSignature = payload |
| 626 |
= data_blob_talloc(tctx, NULL, |
| 627 |
pac_wrapped_struct.ChecksumLength |
| 628 |
+ pac_wrapped_struct.SignatureLength); |
| 629 |
memcpy(&payload.data[0], |
| 630 |
pac_data->pac_srv_sig->signature.data, |
| 631 |
pac_wrapped_struct.ChecksumLength); |
| 632 |
memcpy(&payload.data[pac_wrapped_struct.ChecksumLength], |
| 633 |
pac_data->pac_kdc_sig->signature.data, |
| 634 |
pac_wrapped_struct.SignatureLength); |
| 635 |
|
| 636 |
/* Break the signature length */ |
| 637 |
pac_wrapped_struct.SignatureLength++; |
| 638 |
|
| 639 |
ndr_err = ndr_push_struct_blob(&pac_wrapped, tctx, &pac_wrapped_struct, |
| 640 |
(ndr_push_flags_fn_t)ndr_push_PAC_Validate); |
| 641 |
torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed"); |
| 642 |
|
| 643 |
torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption"); |
| 644 |
|
| 645 |
generic.length = pac_wrapped.length; |
| 646 |
generic.data = pac_wrapped.data; |
| 647 |
|
| 648 |
logon.generic = &generic; |
| 649 |
|
| 650 |
ZERO_STRUCT(auth2); |
| 651 |
netlogon_creds_client_authenticator(creds, &auth); |
| 652 |
r.in.credential = &auth; |
| 653 |
r.in.return_authenticator = &auth2; |
| 654 |
r.in.logon_level = NetlogonGenericInformation; |
| 655 |
r.in.logon = &logon; |
| 656 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 657 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 658 |
r.in.validation_level = NetlogonValidationGenericInfo2; |
| 659 |
|
| 660 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 661 |
status = netlogon_creds_encrypt_samlogon_logon(creds, |
| 662 |
r.in.logon_level, |
| 663 |
r.in.logon, |
| 664 |
auth_type, |
| 665 |
auth_level); |
| 666 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samlogon_logon"); |
| 667 |
|
| 668 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 669 |
"LogonSamLogon failed"); |
| 670 |
|
| 671 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed"); |
| 672 |
|
| 673 |
status = netlogon_creds_client_verify(creds, |
| 674 |
&r.out.return_authenticator->cred, |
| 675 |
auth_type, |
| 676 |
auth_level); |
| 677 |
torture_assert_ntstatus_ok(tctx, status, |
| 678 |
"Credential chaining failed"); |
| 679 |
|
| 680 |
return true; |
| 681 |
} |
| 682 |
|
| 683 |
static bool test_PACVerify_bdc_arcfour(struct torture_context *tctx, |
| 684 |
struct dcerpc_pipe *p, |
| 685 |
struct cli_credentials *credentials) |
| 686 |
{ |
| 687 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_BDC, |
| 688 |
TEST_MACHINE_NAME_BDC, |
| 689 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 690 |
} |
| 691 |
|
| 692 |
static bool test_PACVerify_bdc_aes(struct torture_context *tctx, |
| 693 |
struct dcerpc_pipe *p, |
| 694 |
struct cli_credentials *credentials) |
| 695 |
{ |
| 696 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_BDC, |
| 697 |
TEST_MACHINE_NAME_BDC, |
| 698 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 699 |
} |
| 700 |
|
| 701 |
static bool test_PACVerify_bdc_krb5(struct torture_context *tctx, |
| 702 |
struct dcerpc_pipe *p, |
| 703 |
struct cli_credentials *credentials) |
| 704 |
{ |
| 705 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_BDC, |
| 706 |
TEST_MACHINE_NAME_BDC, |
| 707 |
NETLOGON_NEG_SUPPORTS_KERBEROS_AUTH); |
| 708 |
} |
| 709 |
|
| 710 |
static bool test_PACVerify_workstation_arcfour(struct torture_context *tctx, |
| 711 |
struct dcerpc_pipe *p, |
| 712 |
struct cli_credentials *credentials) |
| 713 |
{ |
| 714 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 715 |
TEST_MACHINE_NAME_WKSTA, |
| 716 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 717 |
} |
| 718 |
|
| 719 |
static bool test_PACVerify_workstation_aes(struct torture_context *tctx, |
| 720 |
struct dcerpc_pipe *p, |
| 721 |
struct cli_credentials *credentials) |
| 722 |
{ |
| 723 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 724 |
TEST_MACHINE_NAME_WKSTA, |
| 725 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 726 |
} |
| 727 |
|
| 728 |
static bool test_PACVerify_workstation_krb5(struct torture_context *tctx, |
| 729 |
struct dcerpc_pipe *p, |
| 730 |
struct cli_credentials *credentials) |
| 731 |
{ |
| 732 |
return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 733 |
TEST_MACHINE_NAME_WKSTA, |
| 734 |
NETLOGON_NEG_SUPPORTS_KERBEROS_AUTH); |
| 735 |
} |
| 736 |
|
| 737 |
#ifdef SAMBA4_USES_HEIMDAL |
| 738 |
static NTSTATUS check_primary_group_in_validation(TALLOC_CTX *mem_ctx, |
| 739 |
uint16_t validation_level, |
| 740 |
const union netr_Validation *validation) |
| 741 |
{ |
| 742 |
const struct netr_SamBaseInfo *base = NULL; |
| 743 |
int i; |
| 744 |
switch (validation_level) { |
| 745 |
case 2: |
| 746 |
if (!validation || !validation->sam2) { |
| 747 |
return NT_STATUS_INVALID_PARAMETER; |
| 748 |
} |
| 749 |
base = &validation->sam2->base; |
| 750 |
break; |
| 751 |
case 3: |
| 752 |
if (!validation || !validation->sam3) { |
| 753 |
return NT_STATUS_INVALID_PARAMETER; |
| 754 |
} |
| 755 |
base = &validation->sam3->base; |
| 756 |
break; |
| 757 |
case 6: |
| 758 |
if (!validation || !validation->sam6) { |
| 759 |
return NT_STATUS_INVALID_PARAMETER; |
| 760 |
} |
| 761 |
base = &validation->sam6->base; |
| 762 |
break; |
| 763 |
default: |
| 764 |
return NT_STATUS_INVALID_LEVEL; |
| 765 |
} |
| 766 |
|
| 767 |
for (i = 0; i < base->groups.count; i++) { |
| 768 |
if (base->groups.rids[i].rid == base->primary_gid) { |
| 769 |
return NT_STATUS_OK; |
| 770 |
} |
| 771 |
} |
| 772 |
return NT_STATUS_INVALID_PARAMETER; |
| 773 |
} |
| 774 |
|
| 775 |
/* Check various ways to get the PAC, in particular check the group membership and |
| 776 |
* other details between the PAC from a normal kinit, S4U2Self and a SamLogon */ |
| 777 |
static bool test_S4U2Self(struct torture_context *tctx, |
| 778 |
struct dcerpc_pipe *p1, |
| 779 |
struct cli_credentials *credentials, |
| 780 |
enum netr_SchannelType secure_channel_type, |
| 781 |
const char *test_machine_name, |
| 782 |
uint32_t negotiate_flags) |
| 783 |
{ |
| 784 |
NTSTATUS status; |
| 785 |
struct dcerpc_pipe *p = NULL; |
| 786 |
struct dcerpc_binding_handle *b = NULL; |
| 787 |
|
| 788 |
struct netr_LogonSamLogon r; |
| 789 |
|
| 790 |
union netr_LogonLevel logon; |
| 791 |
union netr_Validation validation; |
| 792 |
uint8_t authoritative; |
| 793 |
|
| 794 |
struct netr_Authenticator auth, auth2; |
| 795 |
|
| 796 |
DATA_BLOB client_to_server, server_to_client; |
| 797 |
|
| 798 |
struct netlogon_creds_CredentialState *creds; |
| 799 |
struct gensec_security *gensec_client_context; |
| 800 |
struct gensec_security *gensec_server_context; |
| 801 |
struct cli_credentials *client_creds; |
| 802 |
struct cli_credentials *server_creds; |
| 803 |
|
| 804 |
struct auth4_context *auth_context; |
| 805 |
struct auth_session_info *kinit_session_info; |
| 806 |
struct auth_session_info *s4u2self_session_info; |
| 807 |
struct auth_user_info_dc *netlogon_user_info_dc; |
| 808 |
|
| 809 |
struct netr_NetworkInfo ninfo = {}; |
| 810 |
DATA_BLOB names_blob, chal, lm_resp, nt_resp; |
| 811 |
size_t i; |
| 812 |
size_t j; |
| 813 |
size_t k; |
| 814 |
int flags = CLI_CRED_NTLMv2_AUTH; |
| 815 |
|
| 816 |
struct dom_sid *builtin_domain; |
| 817 |
|
| 818 |
struct dom_sid *ai_auth_authority = NULL; |
| 819 |
struct dom_sid *ai_service = NULL; |
| 820 |
struct dom_sid *ai_claims_valid = NULL; |
| 821 |
size_t ai_auth_authority_count = 0; |
| 822 |
size_t ai_service_count = 0; |
| 823 |
size_t ai_claims_valid_count = 0; |
| 824 |
size_t kinit_asserted_identity_index = 0; |
| 825 |
size_t kinit_claims_valid_index = 0; |
| 826 |
size_t s4u2self_asserted_identity_index = 0; |
| 827 |
size_t s4u2self_claims_valid_index = 0; |
| 828 |
bool ok; |
| 829 |
|
| 830 |
TALLOC_CTX *tmp_ctx = talloc_new(tctx); |
| 831 |
|
| 832 |
torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed"); |
| 833 |
|
| 834 |
torture_comment(tctx, |
| 835 |
"Testing S4U2SELF (secure_channel_type: %d, machine: %s, negotiate_flags: 0x%08x\n", |
| 836 |
secure_channel_type, test_machine_name, negotiate_flags); |
| 837 |
|
| 838 |
/* |
| 839 |
* Copy the credentials in order to use a different MEMORY krb5 ccache |
| 840 |
* for each client/server setup. The MEMORY cache identifier is a |
| 841 |
* pointer to the creds container. If we copy it the pointer changes and |
| 842 |
* we will get a new clean memory cache. |
| 843 |
*/ |
| 844 |
client_creds = cli_credentials_shallow_copy(tmp_ctx, |
| 845 |
samba_cmdline_get_creds()); |
| 846 |
torture_assert(tctx, client_creds, "Failed to copy of credentials"); |
| 847 |
/* We use cli_credentials_get_ntlm_response(), so relax krb5 requirements. */ |
| 848 |
cli_credentials_set_kerberos_state(client_creds, |
| 849 |
CRED_USE_KERBEROS_DESIRED, |
| 850 |
CRED_SPECIFIED); |
| 851 |
|
| 852 |
server_creds = cli_credentials_shallow_copy(tmp_ctx, |
| 853 |
credentials); |
| 854 |
torture_assert(tctx, server_creds, "Failed to copy of credentials"); |
| 855 |
|
| 856 |
if (!test_SetupCredentials2(p1, tctx, negotiate_flags, |
| 857 |
server_creds, secure_channel_type, |
| 858 |
&creds)) { |
| 859 |
return false; |
| 860 |
} |
| 861 |
if (!test_SetupCredentialsPipe(p1, tctx, server_creds, creds, |
| 862 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 863 |
return false; |
| 864 |
} |
| 865 |
b = p->binding_handle; |
| 866 |
|
| 867 |
auth_context = talloc_zero(tmp_ctx, struct auth4_context); |
| 868 |
torture_assert(tctx, auth_context != NULL, "talloc_new() failed"); |
| 869 |
|
| 870 |
auth_context->generate_session_info_pac = test_generate_session_info_pac; |
| 871 |
|
| 872 |
/* First, do a normal Kerberos connection */ |
| 873 |
|
| 874 |
status = gensec_client_start(tctx, &gensec_client_context, |
| 875 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 876 |
torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed"); |
| 877 |
|
| 878 |
status = gensec_set_target_hostname(gensec_client_context, test_machine_name); |
| 879 |
|
| 880 |
status = gensec_set_credentials(gensec_client_context, client_creds); |
| 881 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed"); |
| 882 |
|
| 883 |
status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI"); |
| 884 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed"); |
| 885 |
|
| 886 |
status = gensec_server_start(tctx, |
| 887 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx), |
| 888 |
auth_context, &gensec_server_context); |
| 889 |
torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed"); |
| 890 |
|
| 891 |
status = gensec_set_credentials(gensec_server_context, server_creds); |
| 892 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed"); |
| 893 |
|
| 894 |
status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI"); |
| 895 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed"); |
| 896 |
|
| 897 |
server_to_client = data_blob(NULL, 0); |
| 898 |
|
| 899 |
do { |
| 900 |
/* Do a client-server update dance */ |
| 901 |
status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server); |
| 902 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 903 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed"); |
| 904 |
} |
| 905 |
|
| 906 |
status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client); |
| 907 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 908 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed"); |
| 909 |
} |
| 910 |
|
| 911 |
if (NT_STATUS_IS_OK(status)) { |
| 912 |
break; |
| 913 |
} |
| 914 |
} while (1); |
| 915 |
|
| 916 |
/* Extract the PAC using Samba's code */ |
| 917 |
|
| 918 |
status = gensec_session_info(gensec_server_context, gensec_server_context, &kinit_session_info); |
| 919 |
torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed"); |
| 920 |
|
| 921 |
|
| 922 |
/* Now do the dance with S4U2Self */ |
| 923 |
|
| 924 |
/* Wipe out any existing ccache */ |
| 925 |
cli_credentials_invalidate_ccache(client_creds, CRED_SPECIFIED); |
| 926 |
cli_credentials_invalidate_ccache(server_creds, CRED_SPECIFIED); |
| 927 |
cli_credentials_set_impersonate_principal(server_creds, |
| 928 |
cli_credentials_get_principal(client_creds, tmp_ctx), |
| 929 |
talloc_asprintf(tmp_ctx, "host/%s", test_machine_name)); |
| 930 |
|
| 931 |
status = gensec_client_start(tctx, &gensec_client_context, |
| 932 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 933 |
torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed"); |
| 934 |
|
| 935 |
status = gensec_set_target_hostname(gensec_client_context, test_machine_name); |
| 936 |
|
| 937 |
/* We now set the same credentials on both client and server contexts */ |
| 938 |
status = gensec_set_credentials(gensec_client_context, server_creds); |
| 939 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed"); |
| 940 |
|
| 941 |
status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI"); |
| 942 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed"); |
| 943 |
|
| 944 |
status = gensec_server_start(tctx, |
| 945 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx), |
| 946 |
auth_context, &gensec_server_context); |
| 947 |
torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed"); |
| 948 |
|
| 949 |
status = gensec_set_credentials(gensec_server_context, server_creds); |
| 950 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed"); |
| 951 |
|
| 952 |
status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI"); |
| 953 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed"); |
| 954 |
|
| 955 |
server_to_client = data_blob(NULL, 0); |
| 956 |
|
| 957 |
do { |
| 958 |
/* Do a client-server update dance */ |
| 959 |
status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server); |
| 960 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 961 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed"); |
| 962 |
} |
| 963 |
|
| 964 |
status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client); |
| 965 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 966 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed"); |
| 967 |
} |
| 968 |
|
| 969 |
if (NT_STATUS_IS_OK(status)) { |
| 970 |
break; |
| 971 |
} |
| 972 |
} while (1); |
| 973 |
|
| 974 |
/* Don't pollute the remaining tests with the changed credentials */ |
| 975 |
cli_credentials_invalidate_ccache(server_creds, CRED_SPECIFIED); |
| 976 |
cli_credentials_set_target_service(server_creds, NULL); |
| 977 |
cli_credentials_set_impersonate_principal(server_creds, NULL, NULL); |
| 978 |
|
| 979 |
/* Extract the PAC using Samba's code */ |
| 980 |
|
| 981 |
status = gensec_session_info(gensec_server_context, gensec_server_context, &s4u2self_session_info); |
| 982 |
torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed"); |
| 983 |
|
| 984 |
cli_credentials_get_ntlm_username_domain(client_creds, tctx, |
| 985 |
&ninfo.identity_info.account_name.string, |
| 986 |
&ninfo.identity_info.domain_name.string); |
| 987 |
|
| 988 |
/* Now try with SamLogon */ |
| 989 |
generate_random_buffer(ninfo.challenge, |
| 990 |
sizeof(ninfo.challenge)); |
| 991 |
chal = data_blob_const(ninfo.challenge, |
| 992 |
sizeof(ninfo.challenge)); |
| 993 |
|
| 994 |
names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(server_creds), |
| 995 |
cli_credentials_get_domain(server_creds)); |
| 996 |
|
| 997 |
status = cli_credentials_get_ntlm_response(client_creds, tctx, |
| 998 |
&flags, |
| 999 |
chal, |
| 1000 |
NULL, /* server_timestamp */ |
| 1001 |
names_blob, |
| 1002 |
&lm_resp, &nt_resp, |
| 1003 |
NULL, NULL); |
| 1004 |
torture_assert_ntstatus_ok(tctx, status, "cli_credentials_get_ntlm_response failed"); |
| 1005 |
|
| 1006 |
ninfo.lm.data = lm_resp.data; |
| 1007 |
ninfo.lm.length = lm_resp.length; |
| 1008 |
|
| 1009 |
ninfo.nt.data = nt_resp.data; |
| 1010 |
ninfo.nt.length = nt_resp.length; |
| 1011 |
|
| 1012 |
ninfo.identity_info.parameter_control = 0; |
| 1013 |
ninfo.identity_info.logon_id = 0; |
| 1014 |
ninfo.identity_info.workstation.string = cli_credentials_get_workstation(server_creds); |
| 1015 |
|
| 1016 |
logon.network = &ninfo; |
| 1017 |
|
| 1018 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1019 |
r.in.computer_name = cli_credentials_get_workstation(server_creds); |
| 1020 |
r.in.credential = &auth; |
| 1021 |
r.in.return_authenticator = &auth2; |
| 1022 |
r.in.logon_level = NetlogonNetworkInformation; |
| 1023 |
r.in.logon = &logon; |
| 1024 |
r.out.validation = &validation; |
| 1025 |
r.out.authoritative = &authoritative; |
| 1026 |
|
| 1027 |
ZERO_STRUCT(auth2); |
| 1028 |
netlogon_creds_client_authenticator(creds, &auth); |
| 1029 |
|
| 1030 |
r.in.validation_level = 3; |
| 1031 |
|
| 1032 |
status = dcerpc_netr_LogonSamLogon_r(b, tctx, &r); |
| 1033 |
torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed"); |
| 1034 |
|
| 1035 |
torture_assert(tctx, netlogon_creds_client_check(creds, |
| 1036 |
&r.out.return_authenticator->cred), |
| 1037 |
"Credential chaining failed"); |
| 1038 |
|
| 1039 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed"); |
| 1040 |
|
| 1041 |
status = make_user_info_dc_netlogon_validation(tmp_ctx, |
| 1042 |
ninfo.identity_info.account_name.string, |
| 1043 |
r.in.validation_level, |
| 1044 |
r.out.validation, |
| 1045 |
true, /* This user was authenticated */ |
| 1046 |
&netlogon_user_info_dc); |
| 1047 |
|
| 1048 |
torture_assert_ntstatus_ok(tctx, status, "make_user_info_dc_netlogon_validation failed"); |
| 1049 |
|
| 1050 |
/* Check that the primary group is present in validation's RID array */ |
| 1051 |
status = check_primary_group_in_validation(tmp_ctx, r.in.validation_level, r.out.validation); |
| 1052 |
torture_assert_ntstatus_ok(tctx, status, "check_primary_group_in_validation failed"); |
| 1053 |
|
| 1054 |
torture_assert_str_equal(tctx, netlogon_user_info_dc->info->account_name == NULL ? "" : netlogon_user_info_dc->info->account_name, |
| 1055 |
kinit_session_info->info->account_name, "Account name differs for kinit-based PAC"); |
| 1056 |
torture_assert_str_equal(tctx,netlogon_user_info_dc->info->account_name == NULL ? "" : netlogon_user_info_dc->info->account_name, |
| 1057 |
s4u2self_session_info->info->account_name, "Account name differs for S4U2Self"); |
| 1058 |
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"); |
| 1059 |
torture_assert_str_equal(tctx, netlogon_user_info_dc->info->full_name == NULL ? "" : netlogon_user_info_dc->info->full_name, s4u2self_session_info->info->full_name, "Full name differs for S4U2Self"); |
| 1060 |
|
| 1061 |
builtin_domain = dom_sid_parse_talloc(tmp_ctx, SID_BUILTIN); |
| 1062 |
torture_assert_not_null(tctx, builtin_domain, "failed to parse SID"); |
| 1063 |
|
| 1064 |
/* KRB5 might have an additional sid, the asserted identity */ |
| 1065 |
ai_auth_authority = dom_sid_parse_talloc( |
| 1066 |
tmp_ctx, |
| 1067 |
SID_AUTHENTICATION_AUTHORITY_ASSERTED_IDENTITY); |
| 1068 |
torture_assert_not_null(tctx, ai_auth_authority, "failed to parse SID"); |
| 1069 |
|
| 1070 |
ai_service = dom_sid_parse_talloc( |
| 1071 |
tmp_ctx, |
| 1072 |
SID_SERVICE_ASSERTED_IDENTITY); |
| 1073 |
torture_assert_not_null(tctx, ai_service, "failed to parse SID"); |
| 1074 |
|
| 1075 |
/* ...and the Claims Valid SID. */ |
| 1076 |
ai_claims_valid = dom_sid_parse_talloc( |
| 1077 |
tmp_ctx, |
| 1078 |
SID_CLAIMS_VALID); |
| 1079 |
torture_assert_not_null(tctx, ai_claims_valid, "failed to parse SID"); |
| 1080 |
|
| 1081 |
ai_auth_authority_count = 0; |
| 1082 |
ai_service_count = 0; |
| 1083 |
ai_claims_valid_count = 0; |
| 1084 |
for (i = 0; i < kinit_session_info->torture->num_dc_sids; i++) { |
| 1085 |
ok = dom_sid_equal(&kinit_session_info->torture->dc_sids[i].sid, |
| 1086 |
ai_auth_authority); |
| 1087 |
if (ok) { |
| 1088 |
ai_auth_authority_count++; |
| 1089 |
kinit_asserted_identity_index = i; |
| 1090 |
} |
| 1091 |
|
| 1092 |
ok = dom_sid_equal(&kinit_session_info->torture->dc_sids[i].sid, |
| 1093 |
ai_service); |
| 1094 |
if (ok) { |
| 1095 |
ai_service_count++; |
| 1096 |
kinit_asserted_identity_index = i; |
| 1097 |
} |
| 1098 |
|
| 1099 |
ok = dom_sid_equal(&kinit_session_info->torture->dc_sids[i].sid, |
| 1100 |
ai_claims_valid); |
| 1101 |
if (ok) { |
| 1102 |
ai_claims_valid_count++; |
| 1103 |
kinit_claims_valid_index = i; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
torture_assert_int_equal(tctx, ai_auth_authority_count, 1, |
| 1108 |
"Kinit authority asserted identity should be (1)"); |
| 1109 |
torture_assert_int_equal(tctx, ai_service_count, 0, |
| 1110 |
"Kinit service asserted identity should be (0)"); |
| 1111 |
torture_assert_int_equal(tctx, ai_claims_valid_count, 1, |
| 1112 |
"Kinit Claims Valid should be (1)"); |
| 1113 |
|
| 1114 |
ai_auth_authority_count = 0; |
| 1115 |
ai_service_count = 0; |
| 1116 |
ai_claims_valid_count = 0; |
| 1117 |
for (i = 0; i < s4u2self_session_info->torture->num_dc_sids; i++) { |
| 1118 |
ok = dom_sid_equal(&s4u2self_session_info->torture->dc_sids[i].sid, |
| 1119 |
ai_auth_authority); |
| 1120 |
if (ok) { |
| 1121 |
ai_auth_authority_count++; |
| 1122 |
s4u2self_asserted_identity_index = i; |
| 1123 |
} |
| 1124 |
|
| 1125 |
ok = dom_sid_equal(&s4u2self_session_info->torture->dc_sids[i].sid, |
| 1126 |
ai_service); |
| 1127 |
if (ok) { |
| 1128 |
ai_service_count++; |
| 1129 |
s4u2self_asserted_identity_index = i; |
| 1130 |
} |
| 1131 |
|
| 1132 |
ok = dom_sid_equal(&s4u2self_session_info->torture->dc_sids[i].sid, |
| 1133 |
ai_claims_valid); |
| 1134 |
if (ok) { |
| 1135 |
ai_claims_valid_count++; |
| 1136 |
s4u2self_claims_valid_index = i; |
| 1137 |
} |
| 1138 |
} |
| 1139 |
|
| 1140 |
torture_assert_int_equal(tctx, ai_auth_authority_count, 0, |
| 1141 |
"S4U2Self authority asserted identity should be (0)"); |
| 1142 |
torture_assert_int_equal(tctx, ai_service_count, 1, |
| 1143 |
"S4U2Self service asserted identity should be (1)"); |
| 1144 |
torture_assert_int_equal(tctx, ai_claims_valid_count, 1, |
| 1145 |
"S4U2Self Claims Valid should be (1)"); |
| 1146 |
|
| 1147 |
/* |
| 1148 |
* Subtract 2 to account for the Asserted Identity and Claims Valid |
| 1149 |
* SIDs. |
| 1150 |
*/ |
| 1151 |
torture_assert_int_equal(tctx, netlogon_user_info_dc->num_sids, kinit_session_info->torture->num_dc_sids - 2, "Different numbers of domain groups for kinit-based PAC"); |
| 1152 |
torture_assert_int_equal(tctx, netlogon_user_info_dc->num_sids, s4u2self_session_info->torture->num_dc_sids - 2, "Different numbers of domain groups for S4U2Self"); |
| 1153 |
|
| 1154 |
/* Loop over all three SID arrays. */ |
| 1155 |
for (i = 0, j = 0, k = 0; i < netlogon_user_info_dc->num_sids; i++, j++, k++) { |
| 1156 |
while (j == kinit_asserted_identity_index || j == kinit_claims_valid_index) { |
| 1157 |
/* Skip over the asserted identity and Claims Valid SIDs. */ |
| 1158 |
++j; |
| 1159 |
} |
| 1160 |
while (k == s4u2self_asserted_identity_index || k == s4u2self_claims_valid_index) { |
| 1161 |
/* Skip over the asserted identity and Claims Valid SIDs. */ |
| 1162 |
++k; |
| 1163 |
} |
| 1164 |
torture_assert_sid_equal(tctx, &netlogon_user_info_dc->sids[i].sid, &kinit_session_info->torture->dc_sids[j].sid, "Different domain groups for kinit-based PAC"); |
| 1165 |
torture_assert_u32_equal(tctx, netlogon_user_info_dc->sids[i].attrs, kinit_session_info->torture->dc_sids[j].attrs, "Different domain group attrs for kinit-based PAC"); |
| 1166 |
torture_assert_sid_equal(tctx, &netlogon_user_info_dc->sids[i].sid, &s4u2self_session_info->torture->dc_sids[k].sid, "Different domain groups for S4U2Self"); |
| 1167 |
torture_assert_u32_equal(tctx, netlogon_user_info_dc->sids[i].attrs, s4u2self_session_info->torture->dc_sids[k].attrs, "Different domain group attrs for S4U2Self"); |
| 1168 |
torture_assert(tctx, !dom_sid_in_domain(builtin_domain, &s4u2self_session_info->torture->dc_sids[k].sid), "Returned BUILTIN domain in groups for S4U2Self"); |
| 1169 |
torture_assert(tctx, !dom_sid_in_domain(builtin_domain, &kinit_session_info->torture->dc_sids[j].sid), "Returned BUILTIN domain in groups kinit-based PAC"); |
| 1170 |
torture_assert(tctx, !dom_sid_in_domain(builtin_domain, &netlogon_user_info_dc->sids[i].sid), "Returned BUILTIN domain in groups from NETLOGON SamLogon reply"); |
| 1171 |
} |
| 1172 |
|
| 1173 |
return true; |
| 1174 |
} |
| 1175 |
|
| 1176 |
static bool test_S4U2Self_bdc_arcfour(struct torture_context *tctx, |
| 1177 |
struct dcerpc_pipe *p, |
| 1178 |
struct cli_credentials *credentials) |
| 1179 |
{ |
| 1180 |
return test_S4U2Self(tctx, p, credentials, SEC_CHAN_BDC, |
| 1181 |
TEST_MACHINE_NAME_S4U2SELF_BDC, |
| 1182 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 1183 |
} |
| 1184 |
|
| 1185 |
static bool test_S4U2Self_bdc_aes(struct torture_context *tctx, |
| 1186 |
struct dcerpc_pipe *p, |
| 1187 |
struct cli_credentials *credentials) |
| 1188 |
{ |
| 1189 |
return test_S4U2Self(tctx, p, credentials, SEC_CHAN_BDC, |
| 1190 |
TEST_MACHINE_NAME_S4U2SELF_BDC, |
| 1191 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 1192 |
} |
| 1193 |
|
| 1194 |
static bool test_S4U2Self_workstation_arcfour(struct torture_context *tctx, |
| 1195 |
struct dcerpc_pipe *p, |
| 1196 |
struct cli_credentials *credentials) |
| 1197 |
{ |
| 1198 |
return test_S4U2Self(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 1199 |
TEST_MACHINE_NAME_S4U2SELF_WKSTA, |
| 1200 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 1201 |
} |
| 1202 |
|
| 1203 |
static bool test_S4U2Self_workstation_aes(struct torture_context *tctx, |
| 1204 |
struct dcerpc_pipe *p, |
| 1205 |
struct cli_credentials *credentials) |
| 1206 |
{ |
| 1207 |
return test_S4U2Self(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 1208 |
TEST_MACHINE_NAME_S4U2SELF_WKSTA, |
| 1209 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 1210 |
} |
| 1211 |
|
| 1212 |
static bool test_S4U2Proxy(struct torture_context *tctx, |
| 1213 |
struct dcerpc_pipe *p, |
| 1214 |
struct cli_credentials *credentials, |
| 1215 |
enum netr_SchannelType secure_channel_type, |
| 1216 |
const char *test_machine_name, |
| 1217 |
uint32_t negotiate_flags) |
| 1218 |
{ |
| 1219 |
NTSTATUS status; |
| 1220 |
struct gensec_security *gensec_client_context = NULL; |
| 1221 |
struct gensec_security *gensec_server_context = NULL; |
| 1222 |
struct cli_credentials *server_creds = NULL; |
| 1223 |
size_t num_pac_buffers; |
| 1224 |
struct auth4_context *auth_context = NULL; |
| 1225 |
struct auth_session_info *session_info = NULL; |
| 1226 |
struct pac_data *pac_data = NULL; |
| 1227 |
const struct PAC_BUFFER *pac_buf = NULL; |
| 1228 |
char *impersonate_princ = NULL, *self_princ = NULL, *target_princ = NULL; |
| 1229 |
enum ndr_err_code ndr_err; |
| 1230 |
struct PAC_DATA pac_data_struct; |
| 1231 |
struct PAC_CONSTRAINED_DELEGATION *deleg = NULL; |
| 1232 |
|
| 1233 |
DATA_BLOB client_to_server, server_to_client; |
| 1234 |
|
| 1235 |
auth_context = talloc_zero(tctx, struct auth4_context); |
| 1236 |
torture_assert_not_null(tctx, auth_context, "talloc_new() failed"); |
| 1237 |
|
| 1238 |
auth_context->generate_session_info_pac = test_generate_session_info_pac; |
| 1239 |
|
| 1240 |
torture_comment(tctx, |
| 1241 |
"Testing S4U2Proxy (secure_channel_type: %d, machine: %s, negotiate_flags: 0x%08x\n", |
| 1242 |
secure_channel_type, test_machine_name, negotiate_flags); |
| 1243 |
|
| 1244 |
impersonate_princ = cli_credentials_get_principal(samba_cmdline_get_creds(), tctx); |
| 1245 |
torture_assert_not_null(tctx, impersonate_princ, "Failed to get impersonate client name"); |
| 1246 |
|
| 1247 |
server_creds = cli_credentials_shallow_copy(tctx, credentials); |
| 1248 |
torture_assert_not_null(tctx, server_creds, "Failed to copy of credentials"); |
| 1249 |
|
| 1250 |
self_princ = talloc_asprintf(tctx, "host/%s", test_machine_name); |
| 1251 |
cli_credentials_invalidate_ccache(server_creds, CRED_SPECIFIED); |
| 1252 |
cli_credentials_set_impersonate_principal(server_creds, impersonate_princ, self_princ); |
| 1253 |
|
| 1254 |
/* Trigger S4U2Proxy by setting a target_service different than self_principal */ |
| 1255 |
target_princ = talloc_asprintf(tctx, "%s$", test_machine_name); |
| 1256 |
cli_credentials_set_target_service(server_creds, target_princ); |
| 1257 |
|
| 1258 |
status = gensec_client_start(tctx, &gensec_client_context, |
| 1259 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx)); |
| 1260 |
torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed"); |
| 1261 |
|
| 1262 |
status = gensec_set_target_principal(gensec_client_context, target_princ); |
| 1263 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed"); |
| 1264 |
|
| 1265 |
/* We now set the same credentials on both client and server contexts */ |
| 1266 |
status = gensec_set_credentials(gensec_client_context, server_creds); |
| 1267 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed"); |
| 1268 |
|
| 1269 |
status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI"); |
| 1270 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed"); |
| 1271 |
|
| 1272 |
status = gensec_server_start(tctx, |
| 1273 |
lpcfg_gensec_settings(tctx, tctx->lp_ctx), |
| 1274 |
auth_context, &gensec_server_context); |
| 1275 |
torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed"); |
| 1276 |
|
| 1277 |
status = gensec_set_credentials(gensec_server_context, server_creds); |
| 1278 |
torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed"); |
| 1279 |
|
| 1280 |
status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI"); |
| 1281 |
torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed"); |
| 1282 |
|
| 1283 |
server_to_client = data_blob(NULL, 0); |
| 1284 |
|
| 1285 |
do { |
| 1286 |
/* Do a client-server update dance */ |
| 1287 |
status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server); |
| 1288 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 1289 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed"); |
| 1290 |
} |
| 1291 |
|
| 1292 |
status = gensec_update(gensec_server_context, tctx, client_to_server, &server_to_client); |
| 1293 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {; |
| 1294 |
torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed"); |
| 1295 |
} |
| 1296 |
|
| 1297 |
if (NT_STATUS_IS_OK(status)) { |
| 1298 |
break; |
| 1299 |
} |
| 1300 |
} while (1); |
| 1301 |
|
| 1302 |
/* Extract the PAC using Samba's code */ |
| 1303 |
|
| 1304 |
status = gensec_session_info(gensec_server_context, gensec_server_context, &session_info); |
| 1305 |
torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed"); |
| 1306 |
|
| 1307 |
pac_data = talloc_get_type(auth_context->private_data, struct pac_data); |
| 1308 |
|
| 1309 |
torture_assert_not_null(tctx, pac_data, "gensec_update failed to fill in pac_data in auth_context"); |
| 1310 |
torture_assert_not_null(tctx, pac_data->pac_srv_sig, "pac_srv_sig not present"); |
| 1311 |
torture_assert_not_null(tctx, pac_data->pac_kdc_sig, "pac_kdc_sig not present"); |
| 1312 |
|
| 1313 |
ndr_err = ndr_pull_struct_blob(&pac_data->pac_blob, tctx, &pac_data_struct, |
| 1314 |
(ndr_pull_flags_fn_t)ndr_pull_PAC_DATA); |
| 1315 |
torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_pull_struct_blob of PAC_DATA structure failed"); |
| 1316 |
|
| 1317 |
num_pac_buffers = 9; |
| 1318 |
|
| 1319 |
torture_assert_int_equal(tctx, pac_data_struct.version, 0, "version"); |
| 1320 |
torture_assert_int_equal(tctx, pac_data_struct.num_buffers, num_pac_buffers, "num_buffers"); |
| 1321 |
|
| 1322 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_LOGON_INFO); |
| 1323 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_LOGON_INFO"); |
| 1324 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_LOGON_INFO info"); |
| 1325 |
|
| 1326 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_LOGON_NAME); |
| 1327 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_LOGON_NAME"); |
| 1328 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_LOGON_NAME info"); |
| 1329 |
|
| 1330 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_UPN_DNS_INFO); |
| 1331 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_UPN_DNS_INFO"); |
| 1332 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_UPN_DNS_INFO info"); |
| 1333 |
|
| 1334 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_SRV_CHECKSUM); |
| 1335 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_SRV_CHECKSUM"); |
| 1336 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_SRV_CHECKSUM info"); |
| 1337 |
|
| 1338 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_KDC_CHECKSUM); |
| 1339 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_KDC_CHECKSUM"); |
| 1340 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_KDC_CHECKSUM info"); |
| 1341 |
|
| 1342 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_TICKET_CHECKSUM); |
| 1343 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_TICKET_CHECKSUM"); |
| 1344 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_TICKET_CHECKSUM info"); |
| 1345 |
|
| 1346 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_FULL_CHECKSUM); |
| 1347 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_FULL_CHECKSUM"); |
| 1348 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_FULL_CHECKSUM info"); |
| 1349 |
|
| 1350 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_CLIENT_CLAIMS_INFO); |
| 1351 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_CLIENT_CLAIMS_INFO"); |
| 1352 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_CLIENT_CLAIMS_INFO info"); |
| 1353 |
|
| 1354 |
pac_buf = get_pac_buffer(&pac_data_struct, PAC_TYPE_CONSTRAINED_DELEGATION); |
| 1355 |
torture_assert_not_null(tctx, pac_buf, "PAC_TYPE_CONSTRAINED_DELEGATION"); |
| 1356 |
torture_assert_not_null(tctx, pac_buf->info, "PAC_TYPE_CONSTRAINED_DELEGATION info"); |
| 1357 |
|
| 1358 |
deleg = pac_buf->info->constrained_delegation.info; |
| 1359 |
torture_assert_str_equal(tctx, deleg->proxy_target.string, target_princ, "wrong proxy_target"); |
| 1360 |
torture_assert_int_equal(tctx, deleg->num_transited_services, 1, "wrong transited_services number"); |
| 1361 |
torture_assert_str_equal(tctx, deleg->transited_services[0].string, |
| 1362 |
talloc_asprintf(tctx, "%s@%s", self_princ, cli_credentials_get_realm(credentials)), |
| 1363 |
"wrong transited_services[0]"); |
| 1364 |
|
| 1365 |
return netlogon_validate_pac(tctx, p, server_creds, secure_channel_type, test_machine_name, |
| 1366 |
negotiate_flags, pac_data, session_info); |
| 1367 |
} |
| 1368 |
|
| 1369 |
static bool setup_constrained_delegation(struct torture_context *tctx, |
| 1370 |
struct dcerpc_pipe *p, |
| 1371 |
struct test_join *join_ctx, |
| 1372 |
const char *machine_name) |
| 1373 |
{ |
| 1374 |
struct samr_SetUserInfo r; |
| 1375 |
union samr_UserInfo user_info; |
| 1376 |
struct dcerpc_pipe *samr_pipe = torture_join_samr_pipe(join_ctx); |
| 1377 |
const char *server_dn_str = NULL; |
| 1378 |
struct ldb_context *sam_ctx = NULL; |
| 1379 |
struct ldb_dn *server_dn = NULL; |
| 1380 |
struct ldb_message *msg = NULL; |
| 1381 |
char *url = NULL; |
| 1382 |
int ret; |
| 1383 |
|
| 1384 |
url = talloc_asprintf(tctx, "ldap://%s", dcerpc_server_name(p)); |
| 1385 |
sam_ctx = ldb_wrap_connect(tctx, tctx->ev, tctx->lp_ctx, url, NULL, samba_cmdline_get_creds(), 0); |
| 1386 |
torture_assert_not_null(tctx, sam_ctx, "Connection to the SAMDB on DC failed!"); |
| 1387 |
|
| 1388 |
server_dn_str = samdb_search_string(sam_ctx, tctx, ldb_get_default_basedn(sam_ctx), "distinguishedName", |
| 1389 |
"samaccountname=%s$", machine_name); |
| 1390 |
torture_assert_not_null(tctx, server_dn_str, "samdb_search_string()"); |
| 1391 |
|
| 1392 |
server_dn = ldb_dn_new(tctx, sam_ctx, server_dn_str); |
| 1393 |
torture_assert_not_null(tctx, server_dn, "ldb_dn_new()"); |
| 1394 |
|
| 1395 |
msg = ldb_msg_new(tctx); |
| 1396 |
torture_assert_not_null(tctx, msg, "ldb_msg_new()"); |
| 1397 |
|
| 1398 |
msg->dn = server_dn; |
| 1399 |
ret = ldb_msg_add_string(msg, "msDS-AllowedToDelegateTo", talloc_asprintf(tctx, "%s$", machine_name)); |
| 1400 |
torture_assert_int_equal(tctx, ret, 0, "ldb_msg_add_string())"); |
| 1401 |
|
| 1402 |
ret = ldb_modify(sam_ctx, msg); |
| 1403 |
torture_assert_int_equal(tctx, ret, 0, "ldb_modify()"); |
| 1404 |
|
| 1405 |
/* Allow forwardable flag in S4U2Self */ |
| 1406 |
user_info.info16.acct_flags = ACB_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION | ACB_WSTRUST; |
| 1407 |
r.in.user_handle = torture_join_samr_user_policy(join_ctx); |
| 1408 |
r.in.level = 16; |
| 1409 |
r.in.info = &user_info; |
| 1410 |
|
| 1411 |
torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo_r(samr_pipe->binding_handle, tctx, &r), |
| 1412 |
"failed to set ACB_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION info account flags"); |
| 1413 |
torture_assert_ntstatus_ok(tctx, r.out.result, |
| 1414 |
"failed to set ACB_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION into account flags"); |
| 1415 |
|
| 1416 |
return true; |
| 1417 |
} |
| 1418 |
|
| 1419 |
static bool test_S4U2Proxy_workstation_arcfour(struct torture_context *tctx, |
| 1420 |
struct dcerpc_pipe *p, |
| 1421 |
struct cli_credentials *credentials, |
| 1422 |
struct test_join *join_ctx) |
| 1423 |
{ |
| 1424 |
torture_assert(tctx, setup_constrained_delegation(tctx, p, join_ctx, |
| 1425 |
TEST_MACHINE_NAME_S4U2PROXY_WKSTA), |
| 1426 |
"setup_constrained_delegation() failed"); |
| 1427 |
return test_S4U2Proxy(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 1428 |
TEST_MACHINE_NAME_S4U2PROXY_WKSTA, |
| 1429 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 1430 |
} |
| 1431 |
|
| 1432 |
static bool test_S4U2Proxy_workstation_aes(struct torture_context *tctx, |
| 1433 |
struct dcerpc_pipe *p, |
| 1434 |
struct cli_credentials *credentials, |
| 1435 |
struct test_join *join_ctx) |
| 1436 |
{ |
| 1437 |
torture_assert(tctx, setup_constrained_delegation(tctx, p, join_ctx, |
| 1438 |
TEST_MACHINE_NAME_S4U2PROXY_WKSTA), |
| 1439 |
"setup_constrained_delegation() failed"); |
| 1440 |
return test_S4U2Proxy(tctx, p, credentials, SEC_CHAN_WKSTA, |
| 1441 |
TEST_MACHINE_NAME_S4U2PROXY_WKSTA, |
| 1442 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 1443 |
} |
| 1444 |
#endif |
| 1445 |
|
| 1446 |
struct torture_suite *torture_rpc_remote_pac(TALLOC_CTX *mem_ctx) |
| 1447 |
{ |
| 1448 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "pac"); |
| 1449 |
struct torture_rpc_tcase *tcase; |
| 1450 |
|
| 1451 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netr-bdc-arcfour", |
| 1452 |
&ndr_table_netlogon, TEST_MACHINE_NAME_BDC); |
| 1453 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-arcfour", test_PACVerify_bdc_arcfour); |
| 1454 |
|
| 1455 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netr-bdc-aes", |
| 1456 |
&ndr_table_netlogon, TEST_MACHINE_NAME_BDC); |
| 1457 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-aes", test_PACVerify_bdc_aes); |
| 1458 |
|
| 1459 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netr-bdc-krb5", |
| 1460 |
&ndr_table_netlogon, TEST_MACHINE_NAME_BDC); |
| 1461 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-krb5", test_PACVerify_bdc_krb5); |
| 1462 |
|
| 1463 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-arcfour", |
| 1464 |
&ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA); |
| 1465 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-arcfour", test_PACVerify_workstation_arcfour); |
| 1466 |
|
| 1467 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-aes", |
| 1468 |
&ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA); |
| 1469 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-aes", test_PACVerify_workstation_aes); |
| 1470 |
|
| 1471 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-krb5", |
| 1472 |
&ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA); |
| 1473 |
torture_rpc_tcase_add_test_creds(tcase, "verify-sig-krb5", test_PACVerify_workstation_krb5); |
| 1474 |
|
| 1475 |
#ifdef SAMBA4_USES_HEIMDAL |
| 1476 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netr-bdc-arcfour", |
| 1477 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2SELF_BDC); |
| 1478 |
torture_rpc_tcase_add_test_creds(tcase, "s4u2self-arcfour", test_S4U2Self_bdc_arcfour); |
| 1479 |
|
| 1480 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netr-bcd-aes", |
| 1481 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2SELF_BDC); |
| 1482 |
torture_rpc_tcase_add_test_creds(tcase, "s4u2self-aes", test_S4U2Self_bdc_aes); |
| 1483 |
|
| 1484 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-arcfour", |
| 1485 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2SELF_WKSTA); |
| 1486 |
torture_rpc_tcase_add_test_creds(tcase, "s4u2self-arcfour", test_S4U2Self_workstation_arcfour); |
| 1487 |
|
| 1488 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-aes", |
| 1489 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2SELF_WKSTA); |
| 1490 |
torture_rpc_tcase_add_test_creds(tcase, "s4u2self-aes", test_S4U2Self_workstation_aes); |
| 1491 |
|
| 1492 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-arcfour", |
| 1493 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2PROXY_WKSTA); |
| 1494 |
torture_rpc_tcase_add_test_join(tcase, "s4u2proxy-arcfour", test_S4U2Proxy_workstation_arcfour); |
| 1495 |
|
| 1496 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netr-mem-aes", |
| 1497 |
&ndr_table_netlogon, TEST_MACHINE_NAME_S4U2PROXY_WKSTA); |
| 1498 |
torture_rpc_tcase_add_test_join(tcase, "s4u2proxy-aes", test_S4U2Proxy_workstation_aes); |
| 1499 |
#endif |
| 1500 |
return suite; |
| 1501 |
} |