2005-01-01 03:19:08 +03:00
/*
Unix SMB / CIFS implementation .
Kerberos backend for GENSEC
2005-06-28 04:55:44 +04:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2004 - 2005
Copyright ( C ) Stefan Metzmacher < metze @ samba . org > 2004 - 2005
2005-01-01 03:19:08 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-01 03:19:08 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-01 03:19:08 +03:00
*/
# include "includes.h"
2017-05-11 10:04:02 +03:00
# include <tevent.h>
# include "lib/util/tevent_ntstatus.h"
2007-05-17 12:47:04 +04:00
# include "lib/events/events.h"
2005-01-01 03:19:08 +03:00
# include "system/kerberos.h"
2012-04-24 20:37:13 +04:00
# include "system/gssapi.h"
2005-05-11 16:03:48 +04:00
# include "auth/kerberos/kerberos.h"
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/krb5pac.h"
2005-01-01 03:19:08 +03:00
# include "auth/auth.h"
2011-02-10 06:12:51 +03:00
# include <ldb.h>
2006-03-07 14:07:23 +03:00
# include "auth/auth_sam.h"
2014-02-12 15:08:19 +04:00
# include "librpc/gen_ndr/dcerpc.h"
2006-11-07 03:47:36 +03:00
# include "auth/credentials/credentials.h"
# include "auth/credentials/credentials_krb5.h"
# include "auth/gensec/gensec.h"
2013-08-05 09:12:01 +04:00
# include "auth/gensec/gensec_internal.h"
2008-04-02 06:53:27 +04:00
# include "auth/gensec/gensec_proto.h"
2011-07-21 07:20:26 +04:00
# include "auth/gensec/gensec_toplevel_proto.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2008-04-02 06:53:27 +04:00
# include "auth/session_proto.h"
2012-03-30 23:48:54 +04:00
# include "gensec_gssapi.h"
2010-03-26 09:36:02 +03:00
# include "lib/util/util_net.h"
2012-04-01 06:09:22 +04:00
# include "auth/kerberos/pac_utils.h"
2015-06-22 02:23:16 +03:00
# include "auth/kerberos/gssapi_helper.h"
2020-07-03 09:11:20 +03:00
# include "lib/util/smb_strtox.h"
2005-05-16 03:42:11 +04:00
2012-05-08 20:38:20 +04:00
# ifndef gss_mech_spnego
gss_OID_desc spnego_mech_oid_desc =
{ 6 , discard_const_p ( void , " \x2b \x06 \x01 \x05 \x05 \x02 " ) } ;
# define gss_mech_spnego (&spnego_mech_oid_desc)
# endif
2017-04-20 22:24:43 +03:00
_PUBLIC_ NTSTATUS gensec_gssapi_init ( TALLOC_CTX * ) ;
2011-03-19 02:44:20 +03:00
2006-07-21 05:44:24 +04:00
static size_t gensec_gssapi_max_input_size ( struct gensec_security * gensec_security ) ;
static size_t gensec_gssapi_max_wrapped_size ( struct gensec_security * gensec_security ) ;
2015-06-23 13:32:34 +03:00
static size_t gensec_gssapi_sig_size ( struct gensec_security * gensec_security , size_t data_size ) ;
2006-07-21 05:44:24 +04:00
2007-04-12 17:36:49 +04:00
static int gensec_gssapi_destructor ( struct gensec_gssapi_state * gensec_gssapi_state )
2005-01-01 03:19:08 +03:00
{
2015-03-18 23:52:12 +03:00
OM_uint32 min_stat ;
2005-11-02 03:31:22 +03:00
if ( gensec_gssapi_state - > delegated_cred_handle ! = GSS_C_NO_CREDENTIAL ) {
2015-03-18 23:52:12 +03:00
gss_release_cred ( & min_stat ,
& gensec_gssapi_state - > delegated_cred_handle ) ;
2005-11-02 03:31:22 +03:00
}
2005-01-01 03:19:08 +03:00
if ( gensec_gssapi_state - > gssapi_context ! = GSS_C_NO_CONTEXT ) {
2015-03-18 23:52:12 +03:00
gss_delete_sec_context ( & min_stat ,
& gensec_gssapi_state - > gssapi_context ,
GSS_C_NO_BUFFER ) ;
2005-01-01 03:19:08 +03:00
}
if ( gensec_gssapi_state - > server_name ! = GSS_C_NO_NAME ) {
2015-03-18 23:52:12 +03:00
gss_release_name ( & min_stat ,
& gensec_gssapi_state - > server_name ) ;
2005-01-01 03:19:08 +03:00
}
if ( gensec_gssapi_state - > client_name ! = GSS_C_NO_NAME ) {
2015-03-18 23:52:12 +03:00
gss_release_name ( & min_stat ,
& gensec_gssapi_state - > client_name ) ;
2005-01-01 03:19:08 +03:00
}
2008-08-12 16:56:36 +04:00
2005-01-01 03:19:08 +03:00
return 0 ;
}
2017-03-06 11:19:13 +03:00
static NTSTATUS gensec_gssapi_setup_server_principal ( TALLOC_CTX * mem_ctx ,
const char * target_principal ,
const char * service ,
const char * hostname ,
const char * realm ,
const gss_OID mech ,
char * * pserver_principal ,
gss_name_t * pserver_name )
{
char * server_principal = NULL ;
gss_buffer_desc name_token ;
gss_OID name_type ;
OM_uint32 maj_stat , min_stat = 0 ;
if ( target_principal ! = NULL ) {
server_principal = talloc_strdup ( mem_ctx , target_principal ) ;
name_type = GSS_C_NULL_OID ;
} else {
server_principal = talloc_asprintf ( mem_ctx ,
" %s/%s@%s " ,
service , hostname , realm ) ;
name_type = GSS_C_NT_USER_NAME ;
}
if ( server_principal = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
name_token . value = ( uint8_t * ) server_principal ;
name_token . length = strlen ( server_principal ) ;
maj_stat = gss_import_name ( & min_stat ,
& name_token ,
name_type ,
pserver_name ) ;
if ( maj_stat ) {
DBG_WARNING ( " GSS Import name of %s failed: %s \n " ,
server_principal ,
gssapi_error_string ( mem_ctx ,
maj_stat ,
min_stat ,
mech ) ) ;
TALLOC_FREE ( server_principal ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
* pserver_principal = server_principal ;
return NT_STATUS_OK ;
}
2007-12-03 19:41:50 +03:00
static NTSTATUS gensec_gssapi_start ( struct gensec_security * gensec_security )
2005-01-01 03:19:08 +03:00
{
struct gensec_gssapi_state * gensec_gssapi_state ;
2005-05-16 03:42:11 +04:00
krb5_error_code ret ;
2015-10-06 14:25:49 +03:00
# ifdef SAMBA4_USES_HEIMDAL
2009-10-12 21:09:18 +04:00
const char * realm ;
2015-10-06 14:25:49 +03:00
# endif
2006-11-07 09:59:56 +03:00
2010-11-17 09:09:24 +03:00
gensec_gssapi_state = talloc_zero ( gensec_security , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
if ( ! gensec_gssapi_state ) {
return NT_STATUS_NO_MEMORY ;
}
gensec_security - > private_data = gensec_gssapi_state ;
gensec_gssapi_state - > gssapi_context = GSS_C_NO_CONTEXT ;
2023-09-28 18:09:37 +03:00
if ( gensec_security - > channel_bindings ! = NULL ) {
gensec_gssapi_state - > _input_chan_bindings . initiator_addrtype =
gensec_security - > channel_bindings - > initiator_addrtype ;
gensec_gssapi_state - > _input_chan_bindings . initiator_address . value =
gensec_security - > channel_bindings - > initiator_address . data ;
gensec_gssapi_state - > _input_chan_bindings . initiator_address . length =
gensec_security - > channel_bindings - > initiator_address . length ;
gensec_gssapi_state - > _input_chan_bindings . acceptor_addrtype =
gensec_security - > channel_bindings - > acceptor_addrtype ;
gensec_gssapi_state - > _input_chan_bindings . acceptor_address . value =
gensec_security - > channel_bindings - > acceptor_address . data ;
gensec_gssapi_state - > _input_chan_bindings . acceptor_address . length =
gensec_security - > channel_bindings - > acceptor_address . length ;
gensec_gssapi_state - > _input_chan_bindings . application_data . value =
gensec_security - > channel_bindings - > application_data . data ;
gensec_gssapi_state - > _input_chan_bindings . application_data . length =
gensec_security - > channel_bindings - > application_data . length ;
gensec_gssapi_state - > input_chan_bindings =
& gensec_gssapi_state - > _input_chan_bindings ;
} else {
gensec_gssapi_state - > input_chan_bindings = GSS_C_NO_CHANNEL_BINDINGS ;
}
2010-06-24 13:05:41 +04:00
gensec_gssapi_state - > server_name = GSS_C_NO_NAME ;
gensec_gssapi_state - > client_name = GSS_C_NO_NAME ;
2005-01-01 03:19:08 +03:00
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags = 0 ;
2012-03-03 07:33:55 +04:00
gensec_gssapi_state - > expire_time = GENSEC_EXPIRE_TIME_INFINITY ;
2010-06-24 13:05:41 +04:00
2009-06-08 13:06:16 +04:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " delegation_by_kdc_policy " , true ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_DELEG_POLICY_FLAG ;
2009-06-08 13:06:16 +04:00
}
2008-11-02 04:05:48 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " mutual " , true ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_MUTUAL_FLAG ;
2005-11-02 06:48:49 +03:00
}
2016-11-23 13:44:22 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " delegation " , false ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_DELEG_FLAG ;
2005-11-02 06:48:49 +03:00
}
2008-11-02 04:05:48 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " replay " , true ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_REPLAY_FLAG ;
2006-11-08 00:05:45 +03:00
}
2008-11-02 04:05:48 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " sequence " , true ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_SEQUENCE_FLAG ;
2006-02-04 12:53:50 +03:00
}
2005-11-02 06:48:49 +03:00
2013-12-20 11:52:52 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SESSION_KEY ) {
gensec_gssapi_state - > gss_want_flags | = GSS_C_INTEG_FLAG ;
}
2005-01-01 03:19:08 +03:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_INTEG_FLAG ;
2005-01-01 03:19:08 +03:00
}
if ( gensec_security - > want_features & GENSEC_FEATURE_SEAL ) {
2012-01-20 18:56:17 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_INTEG_FLAG ;
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_CONF_FLAG ;
2005-01-01 03:19:08 +03:00
}
2005-05-11 16:03:48 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_DCE_STYLE ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags | = GSS_C_DCE_STYLE ;
2005-05-11 16:03:48 +04:00
}
2005-01-01 03:19:08 +03:00
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_got_flags = 0 ;
2010-06-24 13:05:41 +04:00
2009-07-24 11:37:12 +04:00
switch ( gensec_security - > ops - > auth_type ) {
case DCERPC_AUTH_TYPE_SPNEGO :
gensec_gssapi_state - > gss_oid = gss_mech_spnego ;
break ;
case DCERPC_AUTH_TYPE_KRB5 :
default :
2012-05-08 20:38:20 +04:00
gensec_gssapi_state - > gss_oid =
discard_const_p ( void , gss_mech_krb5 ) ;
2009-07-24 11:37:12 +04:00
break ;
}
2010-06-24 13:05:41 +04:00
ret = smb_krb5_init_context ( gensec_gssapi_state ,
gensec_security - > settings - > lp_ctx ,
& gensec_gssapi_state - > smb_krb5_context ) ;
if ( ret ) {
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_start: smb_krb5_init_context failed (%s) \n " ,
2010-06-24 13:05:41 +04:00
error_message ( ret ) ) ) ;
talloc_free ( gensec_gssapi_state ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
gensec_gssapi_state - > client_cred = NULL ;
gensec_gssapi_state - > server_cred = NULL ;
gensec_gssapi_state - > delegated_cred_handle = GSS_C_NO_CREDENTIAL ;
gensec_gssapi_state - > sasl = false ;
gensec_gssapi_state - > sasl_state = STAGE_GSS_NEG ;
gensec_gssapi_state - > sasl_protection = 0 ;
gensec_gssapi_state - > max_wrap_buf_size
= gensec_setting_int ( gensec_security - > settings , " gensec_gssapi " , " max wrap buf size " , 65536 ) ;
gensec_gssapi_state - > gss_exchange_count = 0 ;
gensec_gssapi_state - > sig_size = 0 ;
talloc_set_destructor ( gensec_gssapi_state , gensec_gssapi_destructor ) ;
2012-05-08 20:38:20 +04:00
# ifdef SAMBA4_USES_HEIMDAL
2010-07-16 08:32:42 +04:00
realm = lpcfg_realm ( gensec_security - > settings - > lp_ctx ) ;
2009-10-12 21:09:18 +04:00
if ( realm ! = NULL ) {
ret = gsskrb5_set_default_realm ( realm ) ;
2006-11-09 03:33:43 +03:00
if ( ret ) {
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_start: gsskrb5_set_default_realm failed \n " ) ) ;
2006-11-09 03:33:43 +03:00
talloc_free ( gensec_gssapi_state ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
}
2006-11-11 06:41:50 +03:00
/* don't do DNS lookups of any kind, it might/will fail for a netbios name */
2019-11-21 21:44:05 +03:00
ret = gsskrb5_set_dns_canonicalize ( false ) ;
2006-11-11 06:41:50 +03:00
if ( ret ) {
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_start: gsskrb5_set_dns_canonicalize failed \n " ) ) ;
2006-11-11 06:41:50 +03:00
talloc_free ( gensec_gssapi_state ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
2012-05-08 20:38:20 +04:00
# endif
2005-01-01 03:19:08 +03:00
return NT_STATUS_OK ;
}
static NTSTATUS gensec_gssapi_server_start ( struct gensec_security * gensec_security )
{
NTSTATUS nt_status ;
2005-10-20 07:47:55 +04:00
int ret ;
2005-01-01 03:19:08 +03:00
struct gensec_gssapi_state * gensec_gssapi_state ;
2005-06-22 06:12:26 +04:00
struct cli_credentials * machine_account ;
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
struct gssapi_creds_container * gcc ;
2005-01-01 03:19:08 +03:00
2007-12-03 19:41:50 +03:00
nt_status = gensec_gssapi_start ( gensec_security ) ;
2005-01-01 03:19:08 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2006-02-04 12:53:50 +03:00
gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
2005-10-20 07:47:55 +04:00
machine_account = gensec_get_credentials ( gensec_security ) ;
2005-06-22 06:12:26 +04:00
2005-10-20 07:47:55 +04:00
if ( ! machine_account ) {
DEBUG ( 3 , ( " No machine account credentials specified \n " ) ) ;
2006-01-28 15:15:24 +03:00
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
2005-06-22 06:12:26 +04:00
} else {
2008-04-17 03:03:18 +04:00
ret = cli_credentials_get_server_gss_creds ( machine_account ,
2008-11-02 04:05:48 +03:00
gensec_security - > settings - > lp_ctx , & gcc ) ;
2005-10-20 07:47:55 +04:00
if ( ret ) {
2016-12-13 13:33:06 +03:00
DEBUG ( 1 , ( " Acquiring acceptor credentials failed: %s \n " ,
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
error_message ( ret ) ) ) ;
2005-10-20 07:47:55 +04:00
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
2005-06-22 06:12:26 +04:00
}
}
r11995: A big kerberos-related update.
This merges Samba4 up to current lorikeet-heimdal, which includes a
replacement for some Samba-specific hacks.
In particular, the credentials system now supplies GSS client and
server credentials. These are imported into GSS with
gss_krb5_import_creds(). Unfortunetly this can't take an MEMORY
keytab, so we now create a FILE based keytab as provision and join
time.
Because the keytab is now created in advance, we don't spend .4s at
negprot doing sha1 s2k calls. Also, because the keytab is read in
real time, any change in the server key will be correctly picked up by
the the krb5 code.
To mark entries in the secrets which should be exported to a keytab,
there is a new kerberosSecret objectClass. The new routine
cli_credentials_update_all_keytabs() searches for these, and updates
the keytabs.
This is called in the provision.js via the ejs wrapper
credentials_update_all_keytabs().
We can now (in theory) use a system-provided /etc/krb5.keytab, if
krb5Keytab: FILE:/etc/krb5.keytab
is added to the secrets.ldb record. By default the attribute
privateKeytab: secrets.keytab
is set, pointing to allow the whole private directory to be moved
without breaking the internal links.
(This used to be commit 6b75573df49c6210e1b9d71e108a9490976bd41d)
2005-12-01 08:20:39 +03:00
gensec_gssapi_state - > server_cred = gcc ;
2005-01-01 03:19:08 +03:00
return NT_STATUS_OK ;
2005-06-22 06:12:26 +04:00
2005-01-01 03:19:08 +03:00
}
2006-02-04 12:53:50 +03:00
static NTSTATUS gensec_gssapi_sasl_server_start ( struct gensec_security * gensec_security )
{
NTSTATUS nt_status ;
struct gensec_gssapi_state * gensec_gssapi_state ;
nt_status = gensec_gssapi_server_start ( gensec_security ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2007-10-07 02:16:19 +04:00
gensec_gssapi_state - > sasl = true ;
2006-02-04 12:53:50 +03:00
}
return nt_status ;
}
2011-10-17 11:22:33 +04:00
static NTSTATUS gensec_gssapi_client_creds ( struct gensec_security * gensec_security ,
struct tevent_context * ev )
2011-10-17 06:46:57 +04:00
{
struct gensec_gssapi_state * gensec_gssapi_state ;
struct gssapi_creds_container * gcc ;
struct cli_credentials * creds = gensec_get_credentials ( gensec_security ) ;
const char * error_string ;
int ret ;
gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
/* Only run this the first time the update() call is made */
if ( gensec_gssapi_state - > client_cred ) {
return NT_STATUS_OK ;
}
ret = cli_credentials_get_client_gss_creds ( creds ,
2011-10-17 11:22:33 +04:00
ev ,
gensec_security - > settings - > lp_ctx , & gcc , & error_string ) ;
2011-10-17 06:46:57 +04:00
switch ( ret ) {
case 0 :
break ;
case EINVAL :
DEBUG ( 3 , ( " Cannot obtain client GSS credentials we need to contact %s : %s \n " , gensec_gssapi_state - > target_principal , error_string ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
case KRB5KDC_ERR_PREAUTH_FAILED :
case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN :
2015-02-07 12:48:30 +03:00
case KRB5KRB_AP_ERR_BAD_INTEGRITY :
2011-10-17 06:46:57 +04:00
DEBUG ( 1 , ( " Wrong username or password: %s \n " , error_string ) ) ;
return NT_STATUS_LOGON_FAILURE ;
2013-11-25 05:09:48 +04:00
case KRB5KDC_ERR_CLIENT_REVOKED :
DEBUG ( 1 , ( " Account locked out: %s \n " , error_string ) ) ;
return NT_STATUS_ACCOUNT_LOCKED_OUT ;
2015-05-05 17:53:24 +03:00
case KRB5_REALM_UNKNOWN :
2011-10-17 06:46:57 +04:00
case KRB5_KDC_UNREACH :
DEBUG ( 3 , ( " Cannot reach a KDC we require to contact %s : %s \n " , gensec_gssapi_state - > target_principal , error_string ) ) ;
return NT_STATUS_NO_LOGON_SERVERS ;
case KRB5_CC_NOTFOUND :
case KRB5_CC_END :
DEBUG ( 2 , ( " Error obtaining ticket we require to contact %s: (possibly due to clock skew between us and the KDC) %s \n " , gensec_gssapi_state - > target_principal , error_string ) ) ;
return NT_STATUS_TIME_DIFFERENCE_AT_DC ;
default :
2023-07-20 12:34:28 +03:00
DEBUG ( 1 , ( " Acquiring initiator credentials failed: %s \n " , error_string ) ) ;
2011-10-17 06:46:57 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
gensec_gssapi_state - > client_cred = gcc ;
if ( ! talloc_reference ( gensec_gssapi_state , gcc ) ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
2007-12-03 19:41:50 +03:00
static NTSTATUS gensec_gssapi_client_start ( struct gensec_security * gensec_security )
2005-01-01 03:19:08 +03:00
{
struct gensec_gssapi_state * gensec_gssapi_state ;
2005-06-28 04:55:44 +04:00
struct cli_credentials * creds = gensec_get_credentials ( gensec_security ) ;
2005-01-01 03:19:08 +03:00
NTSTATUS nt_status ;
2016-12-29 16:00:36 +03:00
2024-03-05 17:33:51 +03:00
nt_status = gensec_kerberos_possible ( gensec_security ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
char * target_name = NULL ;
char * cred_name = NULL ;
2005-07-09 05:58:38 +04:00
2024-03-05 17:33:51 +03:00
target_name = gensec_get_unparsed_target_principal ( gensec_security ,
gensec_security ) ;
cred_name = cli_credentials_get_unparsed_name ( creds ,
gensec_security ) ;
DBG_NOTICE ( " Not using kerberos to %s as %s: %s \n " ,
target_name , cred_name , nt_errstr ( nt_status ) ) ;
2005-01-05 13:21:08 +03:00
2024-03-05 17:33:51 +03:00
TALLOC_FREE ( target_name ) ;
2016-12-29 17:20:00 +03:00
TALLOC_FREE ( cred_name ) ;
2024-03-05 17:33:51 +03:00
return nt_status ;
2016-12-29 17:20:00 +03:00
}
2007-12-03 19:41:50 +03:00
nt_status = gensec_gssapi_start ( gensec_security ) ;
2005-01-01 03:19:08 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2006-02-04 12:53:50 +03:00
gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
2023-09-28 18:09:37 +03:00
# ifdef HAVE_CLIENT_GSS_C_CHANNEL_BOUND_FLAG
/*
* We can only use GSS_C_CHANNEL_BOUND_FLAG if the kerberos library
* supports that in order to add KERB_AP_OPTIONS_CBT .
*
* See :
* https : //github.com/heimdal/heimdal/pull/1234
* https : //github.com/krb5/krb5/pull/1329
*/
if ( ! ( gensec_security - > want_features & GENSEC_FEATURE_CB_OPTIONAL ) ) {
gensec_gssapi_state - > gss_want_flags | = GSS_C_CHANNEL_BOUND_FLAG ;
}
# endif
2011-03-25 17:44:50 +03:00
if ( cli_credentials_get_impersonate_principal ( creds ) ) {
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags & = ~ ( GSS_C_DELEG_FLAG | GSS_C_DELEG_POLICY_FLAG ) ;
2011-03-25 17:44:50 +03:00
}
2005-01-01 03:19:08 +03:00
return NT_STATUS_OK ;
}
2007-12-03 19:41:50 +03:00
static NTSTATUS gensec_gssapi_sasl_client_start ( struct gensec_security * gensec_security )
2006-02-04 12:53:50 +03:00
{
NTSTATUS nt_status ;
struct gensec_gssapi_state * gensec_gssapi_state ;
2007-12-03 19:41:50 +03:00
nt_status = gensec_gssapi_client_start ( gensec_security ) ;
2006-02-04 12:53:50 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2007-10-07 02:16:19 +04:00
gensec_gssapi_state - > sasl = true ;
2006-02-04 12:53:50 +03:00
}
return nt_status ;
}
2017-05-11 10:04:02 +03:00
static NTSTATUS gensec_gssapi_update_internal ( struct gensec_security * gensec_security ,
TALLOC_CTX * out_mem_ctx ,
struct tevent_context * ev ,
const DATA_BLOB in , DATA_BLOB * out )
2005-01-01 03:19:08 +03:00
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2019-07-08 16:49:30 +03:00
NTSTATUS nt_status ;
2005-01-01 03:19:08 +03:00
OM_uint32 maj_stat , min_stat ;
OM_uint32 min_stat2 ;
2014-07-18 14:57:20 +04:00
gss_buffer_desc input_token = { 0 , NULL } ;
gss_buffer_desc output_token = { 0 , NULL } ;
2017-03-08 14:34:59 +03:00
struct cli_credentials * cli_creds = gensec_get_credentials ( gensec_security ) ;
const char * target_principal = gensec_get_target_principal ( gensec_security ) ;
const char * hostname = gensec_get_target_hostname ( gensec_security ) ;
const char * service = gensec_get_target_service ( gensec_security ) ;
2006-11-10 05:44:38 +03:00
gss_OID gss_oid_p = NULL ;
2012-04-20 15:51:22 +04:00
OM_uint32 time_req = 0 ;
2012-03-03 01:02:36 +04:00
OM_uint32 time_rec = 0 ;
struct timeval tv ;
2012-04-20 15:51:22 +04:00
time_req = gensec_setting_int ( gensec_security - > settings ,
" gensec_gssapi " , " requested_life_time " ,
time_req ) ;
2005-01-01 03:19:08 +03:00
input_token . length = in . length ;
input_token . value = in . data ;
2006-02-04 12:53:50 +03:00
switch ( gensec_gssapi_state - > sasl_state ) {
case STAGE_GSS_NEG :
2005-01-01 03:19:08 +03:00
{
2006-02-04 12:53:50 +03:00
switch ( gensec_security - > gensec_role ) {
case GENSEC_CLIENT :
{
2019-09-17 09:05:09 +03:00
const char * client_realm = NULL ;
2012-05-08 20:38:20 +04:00
# ifdef SAMBA4_USES_HEIMDAL
2010-10-11 09:53:08 +04:00
struct gsskrb5_send_to_kdc send_to_kdc ;
krb5_error_code ret ;
2017-05-23 16:05:25 +03:00
# else
bool fallback = false ;
2015-10-06 14:25:49 +03:00
# endif
2011-10-17 06:46:57 +04:00
2011-10-17 11:22:33 +04:00
nt_status = gensec_gssapi_client_creds ( gensec_security , ev ) ;
2011-10-17 06:46:57 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2012-04-22 00:35:48 +04:00
# ifdef SAMBA4_USES_HEIMDAL
2010-10-11 09:53:08 +04:00
send_to_kdc . func = smb_krb5_send_and_recv_func ;
2011-10-17 11:22:33 +04:00
send_to_kdc . ptr = ev ;
2010-10-11 09:53:08 +04:00
min_stat = gsskrb5_set_send_to_kdc ( & send_to_kdc ) ;
if ( min_stat ) {
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_update: gsskrb5_set_send_to_kdc failed \n " ) ) ;
2010-10-11 09:53:08 +04:00
return NT_STATUS_INTERNAL_ERROR ;
}
2012-05-08 20:38:20 +04:00
# endif
2017-03-08 14:34:59 +03:00
2017-03-08 13:03:17 +03:00
/*
* With credentials for
* administrator @ FOREST1 . EXAMPLE . COM this patch changes
* the target_principal for the ldap service of host
* dc2 . forest2 . example . com from
*
* ldap / dc2 . forest2 . example . com @ FOREST1 . EXAMPLE . COM
*
* to
*
* ldap / dc2 . forest2 . example . com @ FOREST2 . EXAMPLE . COM
*
* Typically
* ldap / dc2 . forest2 . example . com @ FOREST1 . EXAMPLE . COM
* should be used in order to allow the KDC of
* FOREST1 . EXAMPLE . COM to generate a referral ticket
* for krbtgt / FOREST2 . EXAMPLE . COM @ FOREST1 . EXAMPLE . COM .
*
* The problem is that KDCs only return such referral
* tickets if there ' s a forest trust between
* FOREST1 . EXAMPLE . COM and FOREST2 . EXAMPLE . COM . If
* there ' s only an external domain trust between
* FOREST1 . EXAMPLE . COM and FOREST2 . EXAMPLE . COM the KDC
* of FOREST1 . EXAMPLE . COM will respond with
* S_PRINCIPAL_UNKNOWN when being asked for
* ldap / dc2 . forest2 . example . com @ FOREST1 . EXAMPLE . COM .
*
* In the case of an external trust the client can
* still ask explicitly for
* krbtgt / FOREST2 . EXAMPLE . COM @ FOREST1 . EXAMPLE . COM and
* the KDC of FOREST1 . EXAMPLE . COM will generate it .
*
* From there the client can use the
* krbtgt / FOREST2 . EXAMPLE . COM @ FOREST1 . EXAMPLE . COM
* ticket and ask a KDC of FOREST2 . EXAMPLE . COM for a
* service ticket for
* ldap / dc2 . forest2 . example . com @ FOREST2 . EXAMPLE . COM .
*
* With Heimdal we ' ll get the fallback on
* S_PRINCIPAL_UNKNOWN behavior when we pass
* ldap / dc2 . forest2 . example . com @ FOREST2 . EXAMPLE . COM as
* target principal . As _krb5_get_cred_kdc_any ( ) first
* calls get_cred_kdc_referral ( ) ( which always starts
* with the client realm ) and falls back to
* get_cred_kdc_capath ( ) ( which starts with the given
* realm ) .
*
* MIT krb5 only tries the given realm of the target
* principal , if we want to autodetect support for
* transitive forest trusts , would have to do the
* fallback ourself .
*/
2019-09-17 09:05:09 +03:00
client_realm = cli_credentials_get_realm ( cli_creds ) ;
2017-03-08 15:10:05 +03:00
# ifndef SAMBA4_USES_HEIMDAL
if ( gensec_gssapi_state - > server_name = = NULL ) {
nt_status = gensec_gssapi_setup_server_principal ( gensec_gssapi_state ,
target_principal ,
service ,
hostname ,
client_realm ,
gensec_gssapi_state - > gss_oid ,
& gensec_gssapi_state - > target_principal ,
& gensec_gssapi_state - > server_name ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
maj_stat = gss_init_sec_context ( & min_stat ,
gensec_gssapi_state - > client_cred - > creds ,
& gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > server_name ,
gensec_gssapi_state - > gss_oid ,
gensec_gssapi_state - > gss_want_flags ,
time_req ,
gensec_gssapi_state - > input_chan_bindings ,
& input_token ,
& gss_oid_p ,
& output_token ,
& gensec_gssapi_state - > gss_got_flags , /* ret flags */
& time_rec ) ;
if ( maj_stat ! = GSS_S_FAILURE ) {
goto init_sec_context_done ;
}
if ( min_stat ! = ( OM_uint32 ) KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN ) {
goto init_sec_context_done ;
}
if ( target_principal ! = NULL ) {
goto init_sec_context_done ;
}
fallback = true ;
TALLOC_FREE ( gensec_gssapi_state - > target_principal ) ;
gss_release_name ( & min_stat2 , & gensec_gssapi_state - > server_name ) ;
}
# endif /* !SAMBA4_USES_HEIMDAL */
2017-03-08 14:34:59 +03:00
if ( gensec_gssapi_state - > server_name = = NULL ) {
2019-09-17 09:05:09 +03:00
const char * server_realm = NULL ;
2017-03-08 13:03:17 +03:00
server_realm = smb_krb5_get_realm_from_hostname ( gensec_gssapi_state ,
hostname ,
client_realm ) ;
if ( server_realm = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2017-05-23 16:05:25 +03:00
# ifndef SAMBA4_USES_HEIMDAL
2017-03-08 15:10:05 +03:00
if ( fallback & &
strequal ( client_realm , server_realm ) ) {
goto init_sec_context_done ;
}
2017-05-23 16:05:25 +03:00
# endif /* !SAMBA4_USES_HEIMDAL */
2017-03-08 15:10:05 +03:00
2017-03-08 14:34:59 +03:00
nt_status = gensec_gssapi_setup_server_principal ( gensec_gssapi_state ,
target_principal ,
service ,
hostname ,
2017-03-08 13:03:17 +03:00
server_realm ,
2017-03-08 14:34:59 +03:00
gensec_gssapi_state - > gss_oid ,
& gensec_gssapi_state - > target_principal ,
& gensec_gssapi_state - > server_name ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
}
2006-02-04 12:53:50 +03:00
maj_stat = gss_init_sec_context ( & min_stat ,
gensec_gssapi_state - > client_cred - > creds ,
& gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > server_name ,
2007-12-12 13:08:32 +03:00
gensec_gssapi_state - > gss_oid ,
2012-01-11 04:26:31 +04:00
gensec_gssapi_state - > gss_want_flags ,
2012-04-20 15:51:22 +04:00
time_req ,
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > input_chan_bindings ,
& input_token ,
2006-11-10 05:44:38 +03:00
& gss_oid_p ,
2006-02-04 12:53:50 +03:00
& output_token ,
2012-01-11 04:26:31 +04:00
& gensec_gssapi_state - > gss_got_flags , /* ret flags */
2012-03-03 01:02:36 +04:00
& time_rec ) ;
2017-03-08 15:10:05 +03:00
goto init_sec_context_done ;
/* JUMP! */
init_sec_context_done :
2006-11-10 05:44:38 +03:00
if ( gss_oid_p ) {
gensec_gssapi_state - > gss_oid = gss_oid_p ;
}
2010-10-11 09:53:08 +04:00
2012-04-22 00:35:48 +04:00
# ifdef SAMBA4_USES_HEIMDAL
2010-10-11 09:53:08 +04:00
send_to_kdc . func = smb_krb5_send_and_recv_func ;
send_to_kdc . ptr = NULL ;
ret = gsskrb5_set_send_to_kdc ( & send_to_kdc ) ;
if ( ret ) {
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_update: gsskrb5_set_send_to_kdc failed \n " ) ) ;
2010-10-11 09:53:08 +04:00
return NT_STATUS_INTERNAL_ERROR ;
}
2012-05-08 20:38:20 +04:00
# endif
2006-02-04 12:53:50 +03:00
break ;
}
case GENSEC_SERVER :
{
maj_stat = gss_accept_sec_context ( & min_stat ,
& gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > server_cred - > creds ,
& input_token ,
gensec_gssapi_state - > input_chan_bindings ,
& gensec_gssapi_state - > client_name ,
& gss_oid_p ,
2006-02-04 14:19:09 +03:00
& output_token ,
2012-01-11 04:26:31 +04:00
& gensec_gssapi_state - > gss_got_flags ,
2012-03-03 01:02:36 +04:00
& time_rec ,
2006-02-04 12:53:50 +03:00
& gensec_gssapi_state - > delegated_cred_handle ) ;
2006-11-10 05:44:38 +03:00
if ( gss_oid_p ) {
gensec_gssapi_state - > gss_oid = gss_oid_p ;
}
2023-09-28 18:09:37 +03:00
# ifdef GSS_C_CHANNEL_BOUND_FLAG
if ( maj_stat = = GSS_S_COMPLETE & &
gensec_security - > channel_bindings ! = NULL & &
! ( gensec_security - > want_features & GENSEC_FEATURE_CB_OPTIONAL ) & &
! ( gensec_gssapi_state - > gss_got_flags & GSS_C_CHANNEL_BOUND_FLAG ) )
{
/*
* If we require valid channel bindings
* we need to check the client provided
* them .
*
* We detect this if
* GSS_C_CHANNEL_BOUND_FLAG is given .
*
* Recent heimdal and MIT releases support this
* with older releases ( e . g . MIT > 1.19 ) .
*
* It means client with zero channel bindings
* on a server with non - zero channel bindings
* won ' t generate GSS_S_BAD_BINDINGS directly
* unless KERB_AP_OPTIONS_CBT was also
* provides by the client .
*
* So we need to convert a missing
* GSS_C_CHANNEL_BOUND_FLAG into
* GSS_S_BAD_BINDINGS by default
* ( unless GENSEC_FEATURE_CB_OPTIONAL is given ) .
*/
maj_stat = GSS_S_BAD_BINDINGS ;
min_stat = 0 ;
}
# endif /* GSS_C_CHANNEL_BOUND_FLAG */
2006-02-04 12:53:50 +03:00
break ;
}
default :
return NT_STATUS_INVALID_PARAMETER ;
}
2005-01-01 03:19:08 +03:00
2006-11-07 09:59:56 +03:00
gensec_gssapi_state - > gss_exchange_count + + ;
2006-02-04 12:53:50 +03:00
if ( maj_stat = = GSS_S_COMPLETE ) {
* out = data_blob_talloc ( out_mem_ctx , output_token . value , output_token . length ) ;
gss_release_buffer ( & min_stat2 , & output_token ) ;
2014-07-29 14:33:49 +04:00
if ( gensec_gssapi_state - > gss_got_flags & GSS_C_DELEG_FLAG & &
gensec_gssapi_state - > delegated_cred_handle ! = GSS_C_NO_CREDENTIAL ) {
2006-02-04 12:53:50 +03:00
DEBUG ( 5 , ( " gensec_gssapi: credentials were delegated \n " ) ) ;
} else {
DEBUG ( 5 , ( " gensec_gssapi: NO credentials were delegated \n " ) ) ;
}
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
2012-03-03 01:02:36 +04:00
tv = timeval_current_ofs ( time_rec , 0 ) ;
gensec_gssapi_state - > expire_time = timeval_to_nttime ( & tv ) ;
2006-02-04 14:19:09 +03:00
/* We may have been invoked as SASL, so there
* is more work to do */
2006-02-04 12:53:50 +03:00
if ( gensec_gssapi_state - > sasl ) {
gensec_gssapi_state - > sasl_state = STAGE_SASL_SSF_NEG ;
return NT_STATUS_MORE_PROCESSING_REQUIRED ;
} else {
gensec_gssapi_state - > sasl_state = STAGE_DONE ;
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 5 , ( " GSSAPI Connection will be cryptographically sealed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 5 , ( " GSSAPI Connection will be cryptographically signed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else {
2006-03-25 03:50:26 +03:00
DEBUG ( 5 , ( " GSSAPI Connection will have no cryptographic protection \n " ) ) ;
2006-02-04 12:53:50 +03:00
}
return NT_STATUS_OK ;
}
} else if ( maj_stat = = GSS_S_CONTINUE_NEEDED ) {
* out = data_blob_talloc ( out_mem_ctx , output_token . value , output_token . length ) ;
gss_release_buffer ( & min_stat2 , & output_token ) ;
return NT_STATUS_MORE_PROCESSING_REQUIRED ;
2023-09-28 18:09:37 +03:00
} else if ( maj_stat = = GSS_S_BAD_BINDINGS ) {
DBG_WARNING ( " Got GSS_S_BAD_BINDINGS \n " ) ;
return NT_STATUS_BAD_BINDINGS ;
2011-06-08 02:55:19 +04:00
} else if ( maj_stat = = GSS_S_CONTEXT_EXPIRED ) {
2015-02-25 15:19:44 +03:00
gss_cred_id_t creds = NULL ;
2011-06-08 02:55:19 +04:00
gss_name_t name ;
gss_buffer_desc buffer ;
OM_uint32 lifetime = 0 ;
gss_cred_usage_t usage ;
const char * role = NULL ;
switch ( gensec_security - > gensec_role ) {
case GENSEC_CLIENT :
creds = gensec_gssapi_state - > client_cred - > creds ;
role = " client " ;
2012-05-17 19:31:09 +04:00
break ;
2011-06-08 02:55:19 +04:00
case GENSEC_SERVER :
creds = gensec_gssapi_state - > server_cred - > creds ;
role = " server " ;
2012-05-17 19:31:09 +04:00
break ;
2011-06-08 02:55:19 +04:00
}
2019-05-08 17:27:57 +03:00
DBG_ERR ( " GSS %s Update(krb5)(%d) failed, credentials "
" expired during GSSAPI handshake! \n " ,
role ,
gensec_gssapi_state - > gss_exchange_count ) ;
2011-06-08 02:55:19 +04:00
maj_stat = gss_inquire_cred ( & min_stat ,
creds ,
& name , & lifetime , & usage , NULL ) ;
if ( maj_stat = = GSS_S_COMPLETE ) {
2015-02-25 15:19:44 +03:00
const char * usage_string = NULL ;
2011-06-08 02:55:19 +04:00
switch ( usage ) {
case GSS_C_BOTH :
usage_string = " GSS_C_BOTH " ;
break ;
case GSS_C_ACCEPT :
usage_string = " GSS_C_ACCEPT " ;
break ;
case GSS_C_INITIATE :
usage_string = " GSS_C_INITIATE " ;
break ;
}
maj_stat = gss_display_name ( & min_stat , name , & buffer , NULL ) ;
if ( maj_stat ) {
buffer . value = NULL ;
buffer . length = 0 ;
}
if ( lifetime > 0 ) {
DEBUG ( 0 , ( " GSSAPI gss_inquire_cred indicates expiry of %*.*s in %u sec for %s \n " ,
( int ) buffer . length , ( int ) buffer . length , ( char * ) buffer . value ,
lifetime , usage_string ) ) ;
} else {
DEBUG ( 0 , ( " GSSAPI gss_inquire_cred indicates %*.*s has already expired for %s \n " ,
( int ) buffer . length , ( int ) buffer . length , ( char * ) buffer . value ,
usage_string ) ) ;
}
gss_release_buffer ( & min_stat , & buffer ) ;
gss_release_name ( & min_stat , & name ) ;
} else if ( maj_stat ! = GSS_S_COMPLETE ) {
2023-09-05 07:04:28 +03:00
DEBUG ( 0 , ( " inquiry of credential lifetime via GSSAPI gss_inquire_cred failed: %s \n " ,
2011-06-08 02:55:19 +04:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
}
return NT_STATUS_INVALID_PARAMETER ;
2012-05-21 20:25:28 +04:00
} else if ( smb_gss_oid_equal ( gensec_gssapi_state - > gss_oid ,
gss_mech_krb5 ) ) {
2006-02-04 12:53:50 +03:00
switch ( min_stat ) {
2021-02-01 16:33:55 +03:00
case ( OM_uint32 ) KRB5KRB_AP_ERR_TKT_NYV :
2010-11-08 08:55:17 +03:00
DEBUG ( 1 , ( " Error with ticket to contact %s: possible clock skew between us and the KDC or target server: %s \n " ,
gensec_gssapi_state - > target_principal ,
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
return NT_STATUS_TIME_DIFFERENCE_AT_DC ; /* Make SPNEGO ignore us, we can't go any further here */
2021-02-01 16:33:55 +03:00
case ( OM_uint32 ) KRB5KRB_AP_ERR_TKT_EXPIRED :
2010-11-08 08:55:17 +03:00
DEBUG ( 1 , ( " Error with ticket to contact %s: ticket is expired, possible clock skew between us and the KDC or target server: %s \n " ,
gensec_gssapi_state - > target_principal ,
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
return NT_STATUS_INVALID_PARAMETER ; /* Make SPNEGO ignore us, we can't go any further here */
2021-02-01 16:33:55 +03:00
case ( OM_uint32 ) KRB5_KDC_UNREACH :
2013-10-16 06:36:46 +04:00
DEBUG ( 3 , ( " Cannot reach a KDC we require in order to obtain a ticket to %s: %s \n " ,
2010-11-08 08:55:17 +03:00
gensec_gssapi_state - > target_principal ,
2010-11-29 13:33:04 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2010-11-08 08:55:17 +03:00
return NT_STATUS_NO_LOGON_SERVERS ; /* Make SPNEGO ignore us, we can't go any further here */
2021-02-01 16:33:55 +03:00
case ( OM_uint32 ) KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN :
2010-11-08 08:55:17 +03:00
DEBUG ( 3 , ( " Server %s is not registered with our KDC: %s \n " ,
gensec_gssapi_state - > target_principal ,
2010-11-29 13:33:04 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_INVALID_PARAMETER ; /* Make SPNEGO ignore us, we can't go any further here */
2021-02-01 16:33:55 +03:00
case ( OM_uint32 ) KRB5KRB_AP_ERR_MSG_TYPE :
2006-02-04 12:53:50 +03:00
/* garbage input, possibly from the auto-mech detection */
return NT_STATUS_INVALID_PARAMETER ;
default :
2010-11-16 01:28:21 +03:00
DEBUG ( 1 , ( " GSS %s Update(krb5)(%d) Update failed: %s \n " ,
gensec_security - > gensec_role = = GENSEC_CLIENT ? " client " : " server " ,
2006-11-07 09:59:56 +03:00
gensec_gssapi_state - > gss_exchange_count ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2015-03-13 16:39:10 +03:00
return NT_STATUS_LOGON_FAILURE ;
2006-02-04 12:53:50 +03:00
}
2005-11-02 03:31:22 +03:00
} else {
2010-11-16 01:28:21 +03:00
DEBUG ( 1 , ( " GSS %s Update(%d) failed: %s \n " ,
gensec_security - > gensec_role = = GENSEC_CLIENT ? " client " : " server " ,
2006-11-07 09:59:56 +03:00
gensec_gssapi_state - > gss_exchange_count ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2015-03-13 16:39:10 +03:00
return NT_STATUS_LOGON_FAILURE ;
2005-11-02 03:31:22 +03:00
}
2006-02-04 12:53:50 +03:00
break ;
}
2006-07-21 05:44:24 +04:00
2006-02-04 12:53:50 +03:00
/* These last two stages are only done if we were invoked as SASL */
case STAGE_SASL_SSF_NEG :
{
switch ( gensec_security - > gensec_role ) {
case GENSEC_CLIENT :
{
uint8_t maxlength_proposed [ 4 ] ;
2006-07-21 05:44:24 +04:00
uint8_t maxlength_accepted [ 4 ] ;
2006-02-04 12:53:50 +03:00
uint8_t security_supported ;
int conf_state ;
gss_qop_t qop_state ;
input_token . length = in . length ;
input_token . value = in . data ;
2006-07-21 05:44:24 +04:00
/* As a client, we have just send a
* zero - length blob to the server ( after the
* normal GSSAPI exchange ) , and it has replied
* with it ' s SASL negotiation */
2006-02-04 12:53:50 +03:00
maj_stat = gss_unwrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
& input_token ,
& output_token ,
& conf_state ,
& qop_state ) ;
if ( GSS_ERROR ( maj_stat ) ) {
DEBUG ( 1 , ( " gensec_gssapi_update: GSS UnWrap of SASL protection negotiation failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
if ( output_token . length < 4 ) {
2022-10-12 03:56:55 +03:00
gss_release_buffer ( & min_stat , & output_token ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2005-11-02 03:31:22 +03:00
2006-02-04 12:53:50 +03:00
memcpy ( maxlength_proposed , output_token . value , 4 ) ;
gss_release_buffer ( & min_stat , & output_token ) ;
2006-07-21 05:44:24 +04:00
2006-02-04 12:53:50 +03:00
/* first byte is the proposed security */
security_supported = maxlength_proposed [ 0 ] ;
maxlength_proposed [ 0 ] = ' \0 ' ;
2006-07-21 05:44:24 +04:00
/* Rest is the proposed max wrap length */
gensec_gssapi_state - > max_wrap_buf_size = MIN ( RIVAL ( maxlength_proposed , 0 ) ,
gensec_gssapi_state - > max_wrap_buf_size ) ;
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection = 0 ;
2010-09-23 09:41:02 +04:00
if ( security_supported & NEG_SEAL ) {
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection | = NEG_SEAL ;
}
2010-09-23 09:41:02 +04:00
}
if ( security_supported & NEG_SIGN ) {
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection | = NEG_SIGN ;
}
2010-09-23 09:41:02 +04:00
}
if ( security_supported & NEG_NONE ) {
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection | = NEG_NONE ;
2010-09-23 09:41:02 +04:00
}
if ( gensec_gssapi_state - > sasl_protection = = 0 ) {
DEBUG ( 1 , ( " Remote server does not support unprotected connections \n " ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
2006-07-21 05:44:24 +04:00
/* Send back the negotiated max length */
RSIVAL ( maxlength_accepted , 0 , gensec_gssapi_state - > max_wrap_buf_size ) ;
maxlength_accepted [ 0 ] = gensec_gssapi_state - > sasl_protection ;
2006-02-04 12:53:50 +03:00
2006-07-21 05:44:24 +04:00
input_token . value = maxlength_accepted ;
input_token . length = sizeof ( maxlength_accepted ) ;
2006-02-04 12:53:50 +03:00
maj_stat = gss_wrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
2007-10-07 02:16:19 +04:00
false ,
2006-02-04 12:53:50 +03:00
GSS_C_QOP_DEFAULT ,
& input_token ,
& conf_state ,
& output_token ) ;
if ( GSS_ERROR ( maj_stat ) ) {
2006-11-07 09:59:56 +03:00
DEBUG ( 1 , ( " GSS Update(SSF_NEG): GSS Wrap failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
* out = data_blob_talloc ( out_mem_ctx , output_token . value , output_token . length ) ;
gss_release_buffer ( & min_stat , & output_token ) ;
/* quirk: This changes the value that gensec_have_feature returns, to be that after SASL negotiation */
gensec_gssapi_state - > sasl_state = STAGE_DONE ;
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 3 , ( " SASL/GSSAPI Connection to server will be cryptographically sealed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 3 , ( " SASL/GSSAPI Connection to server will be cryptographically signed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else {
2023-09-05 07:04:28 +03:00
DEBUG ( 3 , ( " SASL/GSSAPI Connection to server will have no cryptographic protection \n " ) ) ;
2006-02-04 12:53:50 +03:00
}
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
2006-02-04 12:53:50 +03:00
return NT_STATUS_OK ;
}
case GENSEC_SERVER :
{
uint8_t maxlength_proposed [ 4 ] ;
uint8_t security_supported = 0x0 ;
int conf_state ;
2006-07-21 05:44:24 +04:00
/* As a server, we have just been sent a zero-length blob (note this, but it isn't fatal) */
if ( in . length ! = 0 ) {
DEBUG ( 1 , ( " SASL/GSSAPI: client sent non-zero length starting SASL negotiation! \n " ) ) ;
}
/* Give the client some idea what we will support */
RSIVAL ( maxlength_proposed , 0 , gensec_gssapi_state - > max_wrap_buf_size ) ;
2006-02-04 12:53:50 +03:00
/* first byte is the proposed security */
maxlength_proposed [ 0 ] = ' \0 ' ;
gensec_gssapi_state - > sasl_protection = 0 ;
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
security_supported | = NEG_SEAL ;
}
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
security_supported | = NEG_SIGN ;
}
if ( security_supported = = 0 ) {
/* If we don't support anything, this must be 0 */
RSIVAL ( maxlength_proposed , 0 , 0x0 ) ;
}
2006-07-21 05:44:24 +04:00
2006-02-04 12:53:50 +03:00
/* TODO: We may not wish to support this */
security_supported | = NEG_NONE ;
maxlength_proposed [ 0 ] = security_supported ;
input_token . value = maxlength_proposed ;
input_token . length = sizeof ( maxlength_proposed ) ;
maj_stat = gss_wrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
2007-10-07 02:16:19 +04:00
false ,
2006-02-04 12:53:50 +03:00
GSS_C_QOP_DEFAULT ,
& input_token ,
& conf_state ,
& output_token ) ;
if ( GSS_ERROR ( maj_stat ) ) {
2006-11-07 09:59:56 +03:00
DEBUG ( 1 , ( " GSS Update(SSF_NEG): GSS Wrap failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
* out = data_blob_talloc ( out_mem_ctx , output_token . value , output_token . length ) ;
gss_release_buffer ( & min_stat , & output_token ) ;
gensec_gssapi_state - > sasl_state = STAGE_SASL_SSF_ACCEPT ;
return NT_STATUS_MORE_PROCESSING_REQUIRED ;
}
2005-09-28 08:50:02 +04:00
default :
2006-02-04 12:53:50 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
}
/* This is s server-only stage */
case STAGE_SASL_SSF_ACCEPT :
{
2006-07-21 05:44:24 +04:00
uint8_t maxlength_accepted [ 4 ] ;
uint8_t security_accepted ;
2006-02-04 12:53:50 +03:00
int conf_state ;
gss_qop_t qop_state ;
input_token . length = in . length ;
input_token . value = in . data ;
maj_stat = gss_unwrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
& input_token ,
& output_token ,
& conf_state ,
& qop_state ) ;
if ( GSS_ERROR ( maj_stat ) ) {
DEBUG ( 1 , ( " gensec_gssapi_update: GSS UnWrap of SASL protection negotiation failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( out_mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_ACCESS_DENIED ;
2005-05-16 05:31:22 +04:00
}
2006-02-04 12:53:50 +03:00
if ( output_token . length < 4 ) {
2022-10-12 03:56:55 +03:00
gss_release_buffer ( & min_stat , & output_token ) ;
2006-02-04 12:53:50 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2006-07-21 05:44:24 +04:00
memcpy ( maxlength_accepted , output_token . value , 4 ) ;
2006-02-04 12:53:50 +03:00
gss_release_buffer ( & min_stat , & output_token ) ;
/* first byte is the proposed security */
2006-07-21 05:44:24 +04:00
security_accepted = maxlength_accepted [ 0 ] ;
maxlength_accepted [ 0 ] = ' \0 ' ;
2010-09-23 09:20:30 +04:00
2006-07-21 05:44:24 +04:00
/* Rest is the proposed max wrap length */
gensec_gssapi_state - > max_wrap_buf_size = MIN ( RIVAL ( maxlength_accepted , 0 ) ,
gensec_gssapi_state - > max_wrap_buf_size ) ;
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection = 0 ;
2010-09-23 09:20:30 +04:00
if ( security_accepted & NEG_SEAL ) {
if ( ! gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
DEBUG ( 1 , ( " Remote client wanted seal, but gensec refused \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2006-02-04 12:53:50 +03:00
}
2010-09-23 09:20:30 +04:00
gensec_gssapi_state - > sasl_protection | = NEG_SEAL ;
}
if ( security_accepted & NEG_SIGN ) {
if ( ! gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
DEBUG ( 1 , ( " Remote client wanted sign, but gensec refused \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2006-02-04 12:53:50 +03:00
}
2010-09-23 09:20:30 +04:00
gensec_gssapi_state - > sasl_protection | = NEG_SIGN ;
}
if ( security_accepted & NEG_NONE ) {
2006-02-04 12:53:50 +03:00
gensec_gssapi_state - > sasl_protection | = NEG_NONE ;
}
/* quirk: This changes the value that gensec_have_feature returns, to be that after SASL negotiation */
gensec_gssapi_state - > sasl_state = STAGE_DONE ;
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 5 , ( " SASL/GSSAPI Connection from client will be cryptographically sealed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SIGN ) ) {
2010-11-08 04:15:50 +03:00
DEBUG ( 5 , ( " SASL/GSSAPI Connection from client will be cryptographically signed \n " ) ) ;
2006-02-04 12:53:50 +03:00
} else {
2006-03-25 03:50:26 +03:00
DEBUG ( 5 , ( " SASL/GSSAPI Connection from client will have no cryptographic protection \n " ) ) ;
2006-02-04 12:53:50 +03:00
}
* out = data_blob ( NULL , 0 ) ;
return NT_STATUS_OK ;
}
default :
return NT_STATUS_INVALID_PARAMETER ;
2005-01-01 03:19:08 +03:00
}
}
2017-05-11 10:04:02 +03:00
struct gensec_gssapi_update_state {
NTSTATUS status ;
DATA_BLOB out ;
} ;
static struct tevent_req * gensec_gssapi_update_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct gensec_security * gensec_security ,
const DATA_BLOB in )
{
struct tevent_req * req = NULL ;
struct gensec_gssapi_update_state * state = NULL ;
NTSTATUS status ;
req = tevent_req_create ( mem_ctx , & state ,
struct gensec_gssapi_update_state ) ;
if ( req = = NULL ) {
return NULL ;
}
status = gensec_gssapi_update_internal ( gensec_security ,
state , ev , in ,
& state - > out ) ;
state - > status = status ;
if ( NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
tevent_req_done ( req ) ;
return tevent_req_post ( req , ev ) ;
}
if ( tevent_req_nterror ( req , status ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_done ( req ) ;
return tevent_req_post ( req , ev ) ;
}
static NTSTATUS gensec_gssapi_update_recv ( struct tevent_req * req ,
TALLOC_CTX * out_mem_ctx ,
DATA_BLOB * out )
{
struct gensec_gssapi_update_state * state =
tevent_req_data ( req ,
struct gensec_gssapi_update_state ) ;
NTSTATUS status ;
* out = data_blob_null ;
if ( tevent_req_is_nterror ( req , & status ) ) {
tevent_req_received ( req ) ;
return status ;
}
* out = state - > out ;
talloc_steal ( out_mem_ctx , state - > out . data ) ;
status = state - > status ;
tevent_req_received ( req ) ;
return status ;
}
2005-01-01 03:19:08 +03:00
static NTSTATUS gensec_gssapi_wrap ( struct gensec_security * gensec_security ,
TALLOC_CTX * mem_ctx ,
const DATA_BLOB * in ,
DATA_BLOB * out )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
OM_uint32 maj_stat , min_stat ;
gss_buffer_desc input_token , output_token ;
int conf_state ;
input_token . length = in - > length ;
input_token . value = in - > data ;
2006-07-21 05:44:24 +04:00
2005-01-01 03:19:08 +03:00
maj_stat = gss_wrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ,
GSS_C_QOP_DEFAULT ,
& input_token ,
& conf_state ,
& output_token ) ;
if ( GSS_ERROR ( maj_stat ) ) {
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
DEBUG ( 1 , ( " gensec_gssapi_wrap: GSS Wrap failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2005-01-01 03:19:08 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
* out = data_blob_talloc ( mem_ctx , output_token . value , output_token . length ) ;
2005-01-01 03:19:08 +03:00
gss_release_buffer ( & min_stat , & output_token ) ;
2006-07-21 06:05:45 +04:00
if ( gensec_gssapi_state - > sasl ) {
size_t max_wrapped_size = gensec_gssapi_max_wrapped_size ( gensec_security ) ;
if ( max_wrapped_size < out - > length ) {
DEBUG ( 1 , ( " gensec_gssapi_wrap: when wrapped, INPUT data (%u) is grew to be larger than SASL negotiated maximum output size (%u > %u) \n " ,
2006-09-09 14:05:58 +04:00
( unsigned ) in - > length ,
( unsigned ) out - > length ,
2006-07-21 06:05:45 +04:00
( unsigned int ) max_wrapped_size ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
}
2005-01-01 03:19:08 +03:00
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL )
& & ! conf_state ) {
return NT_STATUS_ACCESS_DENIED ;
}
return NT_STATUS_OK ;
}
static NTSTATUS gensec_gssapi_unwrap ( struct gensec_security * gensec_security ,
TALLOC_CTX * mem_ctx ,
const DATA_BLOB * in ,
DATA_BLOB * out )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
OM_uint32 maj_stat , min_stat ;
gss_buffer_desc input_token , output_token ;
int conf_state ;
gss_qop_t qop_state ;
input_token . length = in - > length ;
input_token . value = in - > data ;
2006-07-21 05:44:24 +04:00
if ( gensec_gssapi_state - > sasl ) {
size_t max_wrapped_size = gensec_gssapi_max_wrapped_size ( gensec_security ) ;
if ( max_wrapped_size < in - > length ) {
DEBUG ( 1 , ( " gensec_gssapi_unwrap: WRAPPED data is larger than SASL negotiated maximum size \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
}
2021-07-20 01:48:41 +03:00
/*
* FIXME : input_message_buffer is marked const , but gss_unwrap ( ) may
* modify it ( see calls to rrc_rotate ( ) in _gssapi_unwrap_cfx ( ) ) .
*/
2005-01-01 03:19:08 +03:00
maj_stat = gss_unwrap ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
& input_token ,
& output_token ,
& conf_state ,
& qop_state ) ;
if ( GSS_ERROR ( maj_stat ) ) {
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
DEBUG ( 1 , ( " gensec_gssapi_unwrap: GSS UnWrap failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2005-01-01 03:19:08 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
r10066: This is the second in my patches to work on Samba4's kerberos support,
with an aim to make the code simpiler and more correct.
Gone is the old (since the very early Samba 3.0 krb5 days) 'iterate over
all keytypes)' code in gensec_krb5, we now follow the approach used in
gensec_gssapi, and use a keytab.
I have also done a lot of work in the GSSAPI code, to try and reduce
the diff between us and upstream heimdal. It was becoming hard to
track patches in this code, and I also want this patch (the DCE_STYLE
support) to be in a 'manageable' state for when lha considers it for
merging. (metze assures me it still has memory leak problems, but
I've started to address some of that).
This patch also includes a simple update of other code to current
heimdal, as well as changes we need for better PAC verification.
On the PAC side of things we now match windows member servers by
checking the name and authtime on an incoming PAC. Not generating these
right was the cause of the PAC pain, and so now both the main code and
torture test validate this behaviour.
One thing doesn't work with this patch:
- the sealing of RPC pipes with kerberos, Samba -> Samba seems
broken. I'm pretty sure this is related to AES, and the need to break
apart the gss_wrap interface.
Andrew Bartlett
(This used to be commit a3aba57c00a9c5318f4706db55d03f64e8bea60c)
2005-09-08 01:52:50 +04:00
* out = data_blob_talloc ( mem_ctx , output_token . value , output_token . length ) ;
2005-01-01 03:19:08 +03:00
gss_release_buffer ( & min_stat , & output_token ) ;
if ( gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL )
& & ! conf_state ) {
return NT_STATUS_ACCESS_DENIED ;
}
return NT_STATUS_OK ;
}
2006-07-21 05:44:24 +04:00
/* Find out the maximum input size negotiated on this connection */
static size_t gensec_gssapi_max_input_size ( struct gensec_security * gensec_security )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2006-07-21 05:44:24 +04:00
OM_uint32 maj_stat , min_stat ;
OM_uint32 max_input_size ;
maj_stat = gss_wrap_size_limit ( & min_stat ,
gensec_gssapi_state - > gssapi_context ,
gensec_have_feature ( gensec_security , GENSEC_FEATURE_SEAL ) ,
GSS_C_QOP_DEFAULT ,
gensec_gssapi_state - > max_wrap_buf_size ,
& max_input_size ) ;
if ( GSS_ERROR ( maj_stat ) ) {
TALLOC_CTX * mem_ctx = talloc_new ( NULL ) ;
2013-02-12 08:37:09 +04:00
DEBUG ( 1 , ( " gensec_gssapi_max_input_size: determining signature size with gss_wrap_size_limit failed: %s \n " ,
2006-11-07 03:47:36 +03:00
gssapi_error_string ( mem_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
2006-07-21 05:44:24 +04:00
talloc_free ( mem_ctx ) ;
return 0 ;
}
return max_input_size ;
}
/* Find out the maximum output size negotiated on this connection */
static size_t gensec_gssapi_max_wrapped_size ( struct gensec_security * gensec_security )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state = talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ; ;
2006-07-21 05:44:24 +04:00
return gensec_gssapi_state - > max_wrap_buf_size ;
}
2005-05-11 16:03:48 +04:00
static NTSTATUS gensec_gssapi_seal_packet ( struct gensec_security * gensec_security ,
TALLOC_CTX * mem_ctx ,
uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
DATA_BLOB * sig )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2015-06-23 13:32:34 +03:00
bool hdr_signing = false ;
size_t sig_size = 0 ;
NTSTATUS status ;
2005-05-11 16:03:48 +04:00
2014-01-03 18:30:46 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN_PKT_HEADER ) {
2015-06-23 13:32:34 +03:00
hdr_signing = true ;
2014-01-03 18:30:46 +04:00
}
2015-06-23 13:32:34 +03:00
sig_size = gensec_gssapi_sig_size ( gensec_security , length ) ;
2005-05-11 16:03:48 +04:00
2015-06-23 13:32:34 +03:00
status = gssapi_seal_packet ( gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > gss_oid ,
hdr_signing , sig_size ,
data , length ,
whole_pdu , pdu_length ,
mem_ctx , sig ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2015-06-26 06:05:48 +03:00
DEBUG ( 0 , ( " gssapi_seal_packet(hdr_signing=%u,sig_size=%zu, "
" data=%zu,pdu=%zu) failed: %s \n " ,
2015-06-23 13:32:34 +03:00
hdr_signing , sig_size , length , pdu_length ,
nt_errstr ( status ) ) ) ;
return status ;
2005-05-11 16:03:48 +04:00
}
return NT_STATUS_OK ;
}
static NTSTATUS gensec_gssapi_unseal_packet ( struct gensec_security * gensec_security ,
uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
const DATA_BLOB * sig )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2015-06-23 13:32:34 +03:00
bool hdr_signing = false ;
NTSTATUS status ;
2005-05-11 16:03:48 +04:00
2014-01-03 18:30:46 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN_PKT_HEADER ) {
2015-06-23 13:32:34 +03:00
hdr_signing = true ;
2005-05-11 16:03:48 +04:00
}
2015-06-23 13:32:34 +03:00
status = gssapi_unseal_packet ( gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > gss_oid ,
hdr_signing ,
data , length ,
whole_pdu , pdu_length ,
sig ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2015-06-26 06:05:48 +03:00
DEBUG ( 0 , ( " gssapi_unseal_packet(hdr_signing=%u,sig_size=%zu, "
" data=%zu,pdu=%zu) failed: %s \n " ,
2015-06-23 13:32:34 +03:00
hdr_signing , sig - > length , length , pdu_length ,
nt_errstr ( status ) ) ) ;
return status ;
2005-05-11 16:03:48 +04:00
}
return NT_STATUS_OK ;
}
static NTSTATUS gensec_gssapi_sign_packet ( struct gensec_security * gensec_security ,
TALLOC_CTX * mem_ctx ,
const uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
DATA_BLOB * sig )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2015-06-23 13:32:34 +03:00
bool hdr_signing = false ;
NTSTATUS status ;
2005-05-11 16:03:48 +04:00
2008-08-06 23:30:17 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN_PKT_HEADER ) {
2015-06-23 13:32:34 +03:00
hdr_signing = true ;
2008-08-06 23:30:17 +04:00
}
2005-05-11 16:03:48 +04:00
2015-06-23 13:32:34 +03:00
status = gssapi_sign_packet ( gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > gss_oid ,
hdr_signing ,
data , length ,
whole_pdu , pdu_length ,
mem_ctx , sig ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " gssapi_sign_packet(hdr_signing=%u, "
2015-06-26 06:05:48 +03:00
" data=%zu,pdu=%zu) failed: %s \n " ,
2015-06-23 13:32:34 +03:00
hdr_signing , length , pdu_length ,
nt_errstr ( status ) ) ) ;
return status ;
2005-05-11 16:03:48 +04:00
}
return NT_STATUS_OK ;
}
static NTSTATUS gensec_gssapi_check_packet ( struct gensec_security * gensec_security ,
const uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
const DATA_BLOB * sig )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2015-06-23 13:32:34 +03:00
bool hdr_signing = false ;
NTSTATUS status ;
2005-05-11 16:03:48 +04:00
2008-08-06 23:30:17 +04:00
if ( gensec_security - > want_features & GENSEC_FEATURE_SIGN_PKT_HEADER ) {
2015-06-23 13:32:34 +03:00
hdr_signing = true ;
2008-08-06 23:30:17 +04:00
}
2005-05-11 16:03:48 +04:00
2015-06-23 13:32:34 +03:00
status = gssapi_check_packet ( gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > gss_oid ,
hdr_signing ,
data , length ,
whole_pdu , pdu_length ,
sig ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2015-06-26 06:05:48 +03:00
DEBUG ( 0 , ( " gssapi_check_packet(hdr_signing=%u,sig_size=%zu, "
" data=%zu,pdu=%zu) failed: %s \n " ,
2015-06-23 13:32:34 +03:00
hdr_signing , sig - > length , length , pdu_length ,
nt_errstr ( status ) ) ) ;
return status ;
2005-05-11 16:03:48 +04:00
}
return NT_STATUS_OK ;
}
2006-02-04 12:53:50 +03:00
/* Try to figure out what features we actually got on the connection */
2007-10-07 02:16:19 +04:00
static bool gensec_gssapi_have_feature ( struct gensec_security * gensec_security ,
2005-02-10 08:22:53 +03:00
uint32_t feature )
2005-01-01 03:19:08 +03:00
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-01-01 03:19:08 +03:00
if ( feature & GENSEC_FEATURE_SIGN ) {
2006-02-04 12:53:50 +03:00
/* If we are going GSSAPI SASL, then we honour the second negotiation */
if ( gensec_gssapi_state - > sasl
& & gensec_gssapi_state - > sasl_state = = STAGE_DONE ) {
return ( ( gensec_gssapi_state - > sasl_protection & NEG_SIGN )
2012-01-11 04:26:31 +04:00
& & ( gensec_gssapi_state - > gss_got_flags & GSS_C_INTEG_FLAG ) ) ;
2006-02-04 12:53:50 +03:00
}
2012-01-11 04:26:31 +04:00
return gensec_gssapi_state - > gss_got_flags & GSS_C_INTEG_FLAG ;
2005-01-01 03:19:08 +03:00
}
if ( feature & GENSEC_FEATURE_SEAL ) {
2006-02-04 12:53:50 +03:00
/* If we are going GSSAPI SASL, then we honour the second negotiation */
if ( gensec_gssapi_state - > sasl
& & gensec_gssapi_state - > sasl_state = = STAGE_DONE ) {
return ( ( gensec_gssapi_state - > sasl_protection & NEG_SEAL )
2012-01-11 04:26:31 +04:00
& & ( gensec_gssapi_state - > gss_got_flags & GSS_C_CONF_FLAG ) ) ;
2006-02-04 12:53:50 +03:00
}
2012-01-11 04:26:31 +04:00
return gensec_gssapi_state - > gss_got_flags & GSS_C_CONF_FLAG ;
2005-01-01 03:19:08 +03:00
}
2005-05-11 16:03:48 +04:00
if ( feature & GENSEC_FEATURE_SESSION_KEY ) {
2006-02-04 12:53:50 +03:00
/* Only for GSSAPI/Krb5 */
2012-05-21 20:25:28 +04:00
if ( smb_gss_oid_equal ( gensec_gssapi_state - > gss_oid ,
gss_mech_krb5 ) ) {
2007-10-07 02:16:19 +04:00
return true ;
2005-05-11 16:03:48 +04:00
}
2005-08-20 10:08:52 +04:00
}
if ( feature & GENSEC_FEATURE_DCE_STYLE ) {
2012-01-11 04:26:31 +04:00
return gensec_gssapi_state - > gss_got_flags & GSS_C_DCE_STYLE ;
2005-08-20 10:08:52 +04:00
}
2008-08-12 17:02:02 +04:00
if ( feature & GENSEC_FEATURE_NEW_SPNEGO ) {
NTSTATUS status ;
2012-02-17 06:36:35 +04:00
uint32_t keytype ;
2008-08-12 17:02:02 +04:00
2012-01-11 04:26:31 +04:00
if ( ! ( gensec_gssapi_state - > gss_got_flags & GSS_C_INTEG_FLAG ) ) {
2008-08-12 17:02:02 +04:00
return false ;
}
2008-11-02 04:05:48 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " force_new_spnego " , false ) ) {
2008-08-12 17:02:02 +04:00
return true ;
}
2008-11-02 04:05:48 +03:00
if ( gensec_setting_bool ( gensec_security - > settings , " gensec_gssapi " , " disable_new_spnego " , false ) ) {
2008-08-12 17:02:02 +04:00
return false ;
}
2012-02-17 06:36:35 +04:00
status = gssapi_get_session_key ( gensec_gssapi_state ,
gensec_gssapi_state - > gssapi_context , NULL , & keytype ) ;
/*
* We should do a proper sig on the mechListMic unless
* we know we have to be backwards compatible with
* earlier windows versions .
*
* Negotiating a non - krb5
* mech for example should be regarded as having
* NEW_SPNEGO
*/
if ( NT_STATUS_IS_OK ( status ) ) {
switch ( keytype ) {
case ENCTYPE_DES_CBC_CRC :
case ENCTYPE_DES_CBC_MD5 :
case ENCTYPE_ARCFOUR_HMAC :
case ENCTYPE_DES3_CBC_SHA1 :
return false ;
}
2008-08-12 17:02:02 +04:00
}
2012-02-17 06:36:35 +04:00
return true ;
2008-08-12 17:02:02 +04:00
}
2006-02-04 12:53:50 +03:00
/* We can always do async (rather than strict request/reply) packets. */
2005-08-20 10:08:52 +04:00
if ( feature & GENSEC_FEATURE_ASYNC_REPLIES ) {
2007-10-07 02:16:19 +04:00
return true ;
2005-05-12 06:07:53 +04:00
}
2013-12-31 12:54:54 +04:00
if ( feature & GENSEC_FEATURE_SIGN_PKT_HEADER ) {
2017-05-12 09:05:03 +03:00
return true ;
2013-12-31 12:54:54 +04:00
}
2007-10-07 02:16:19 +04:00
return false ;
2005-01-01 03:19:08 +03:00
}
2012-03-03 07:33:55 +04:00
static NTTIME gensec_gssapi_expire_time ( struct gensec_security * gensec_security )
{
struct gensec_gssapi_state * gensec_gssapi_state =
talloc_get_type_abort ( gensec_security - > private_data ,
struct gensec_gssapi_state ) ;
return gensec_gssapi_state - > expire_time ;
}
2006-02-04 12:53:50 +03:00
/*
2023-09-05 07:04:28 +03:00
* Extract the ' session key ' needed by SMB signing and ncacn_np
2006-02-04 12:53:50 +03:00
* ( for encrypting some passwords ) .
*
* This breaks all the abstractions , but what do you expect . . .
*/
2005-05-11 16:03:48 +04:00
static NTSTATUS gensec_gssapi_session_key ( struct gensec_security * gensec_security ,
2011-08-01 09:39:01 +04:00
TALLOC_CTX * mem_ctx ,
2005-05-11 16:03:48 +04:00
DATA_BLOB * session_key )
{
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2012-02-17 06:36:35 +04:00
return gssapi_get_session_key ( mem_ctx , gensec_gssapi_state - > gssapi_context , session_key , NULL ) ;
2006-11-07 03:47:36 +03:00
}
2006-02-04 12:53:50 +03:00
/* Get some basic (and authorization) information about the user on
* this session . This uses either the PAC ( if present ) or a local
* database lookup */
2005-05-11 16:03:48 +04:00
static NTSTATUS gensec_gssapi_session_info ( struct gensec_security * gensec_security ,
2011-12-29 15:31:36 +04:00
TALLOC_CTX * mem_ctx ,
2006-01-31 04:50:54 +03:00
struct auth_session_info * * _session_info )
2005-05-11 16:03:48 +04:00
{
NTSTATUS nt_status ;
2011-12-29 15:31:36 +04:00
TALLOC_CTX * tmp_ctx ;
2006-11-07 03:47:36 +03:00
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2005-05-11 16:03:48 +04:00
struct auth_session_info * session_info = NULL ;
OM_uint32 maj_stat , min_stat ;
2011-12-28 10:48:45 +04:00
DATA_BLOB pac_blob , * pac_blob_ptr = NULL ;
gss_buffer_desc name_token ;
char * principal_string ;
2005-05-11 16:03:48 +04:00
2011-12-29 15:31:36 +04:00
tmp_ctx = talloc_named ( mem_ctx , 0 , " gensec_gssapi_session_info context " ) ;
NT_STATUS_HAVE_NO_MEMORY ( tmp_ctx ) ;
2005-06-28 04:55:44 +04:00
2011-12-28 10:48:45 +04:00
maj_stat = gss_display_name ( & min_stat ,
gensec_gssapi_state - > client_name ,
& name_token ,
NULL ) ;
if ( GSS_ERROR ( maj_stat ) ) {
DEBUG ( 1 , ( " GSS display_name failed: %s \n " ,
2011-12-29 15:31:36 +04:00
gssapi_error_string ( tmp_ctx , maj_stat , min_stat , gensec_gssapi_state - > gss_oid ) ) ) ;
talloc_free ( tmp_ctx ) ;
2011-12-28 10:48:45 +04:00
return NT_STATUS_FOOBAR ;
}
2011-12-29 15:31:36 +04:00
principal_string = talloc_strndup ( tmp_ctx ,
2011-12-28 10:48:45 +04:00
( const char * ) name_token . value ,
name_token . length ) ;
gss_release_buffer ( & min_stat , & name_token ) ;
if ( ! principal_string ) {
2011-12-29 15:31:36 +04:00
talloc_free ( tmp_ctx ) ;
2011-12-28 10:48:45 +04:00
return NT_STATUS_NO_MEMORY ;
}
2011-12-29 15:31:36 +04:00
nt_status = gssapi_obtain_pac_blob ( tmp_ctx , gensec_gssapi_state - > gssapi_context ,
2011-04-21 06:38:51 +04:00
gensec_gssapi_state - > client_name ,
& pac_blob ) ;
2005-06-28 04:55:44 +04:00
2005-10-24 02:20:42 +04:00
/* IF we have the PAC - otherwise we need to get this
2023-07-20 12:34:28 +03:00
* data from elsewhere - local ldb , or ( TODO ) lookup of some
2005-10-24 02:20:42 +04:00
* kind . . .
*/
2011-04-21 06:38:51 +04:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2011-12-28 10:48:45 +04:00
pac_blob_ptr = & pac_blob ;
}
2011-12-29 15:31:36 +04:00
nt_status = gensec_generate_session_info_pac ( tmp_ctx ,
2011-12-28 10:48:45 +04:00
gensec_security ,
gensec_gssapi_state - > smb_krb5_context ,
pac_blob_ptr , principal_string ,
gensec_get_remote_address ( gensec_security ) ,
& session_info ) ;
2006-01-31 04:50:54 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2011-12-29 15:31:36 +04:00
talloc_free ( tmp_ctx ) ;
2006-01-31 04:50:54 +03:00
return nt_status ;
}
2005-05-11 16:03:48 +04:00
2011-08-01 09:39:01 +04:00
nt_status = gensec_gssapi_session_key ( gensec_security , session_info , & session_info - > session_key ) ;
2006-01-31 04:50:54 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2011-12-29 15:31:36 +04:00
talloc_free ( tmp_ctx ) ;
2006-01-31 04:50:54 +03:00
return nt_status ;
}
2005-05-11 16:03:48 +04:00
2014-07-29 14:33:49 +04:00
if ( gensec_gssapi_state - > gss_got_flags & GSS_C_DELEG_FLAG & &
gensec_gssapi_state - > delegated_cred_handle ! = GSS_C_NO_CREDENTIAL ) {
2005-11-02 03:31:22 +03:00
krb5_error_code ret ;
2010-02-25 08:16:33 +03:00
const char * error_string ;
2005-11-02 03:31:22 +03:00
DEBUG ( 10 , ( " gensec_gssapi: delegated credentials supplied by client \n " ) ) ;
2016-12-21 23:49:36 +03:00
/*
* Create anonymous credentials for now .
*
* We will update them with the provided client gss creds .
*/
session_info - > credentials = cli_credentials_init_anon ( session_info ) ;
if ( session_info - > credentials = = NULL ) {
2011-12-29 15:31:36 +04:00
talloc_free ( tmp_ctx ) ;
2005-11-02 03:31:22 +03:00
return NT_STATUS_NO_MEMORY ;
}
ret = cli_credentials_set_client_gss_creds ( session_info - > credentials ,
2010-07-16 08:32:42 +04:00
gensec_security - > settings - > lp_ctx ,
2005-11-02 03:31:22 +03:00
gensec_gssapi_state - > delegated_cred_handle ,
2010-02-25 08:16:33 +03:00
CRED_SPECIFIED , & error_string ) ;
2005-11-02 03:31:22 +03:00
if ( ret ) {
2011-12-29 15:31:36 +04:00
talloc_free ( tmp_ctx ) ;
2010-02-25 08:16:33 +03:00
DEBUG ( 2 , ( " Failed to get gss creds: %s \n " , error_string ) ) ;
2005-11-02 03:31:22 +03:00
return NT_STATUS_NO_MEMORY ;
}
2007-04-17 07:49:46 +04:00
/* This credential handle isn't useful for password authentication, so ensure nobody tries to do that */
2020-08-19 16:46:11 +03:00
cli_credentials_set_kerberos_state ( session_info - > credentials ,
CRED_USE_KERBEROS_REQUIRED ,
CRED_SPECIFIED ) ;
2007-04-17 07:49:46 +04:00
2005-11-02 03:31:22 +03:00
/* It has been taken from this place... */
gensec_gssapi_state - > delegated_cred_handle = GSS_C_NO_CREDENTIAL ;
2014-07-29 14:33:49 +04:00
} else {
DEBUG ( 10 , ( " gensec_gssapi: NO delegated credentials supplied by client \n " ) ) ;
2005-11-02 03:31:22 +03:00
}
2014-07-29 14:33:49 +04:00
2011-12-29 15:31:36 +04:00
* _session_info = talloc_steal ( mem_ctx , session_info ) ;
talloc_free ( tmp_ctx ) ;
2005-05-11 16:03:48 +04:00
return NT_STATUS_OK ;
}
2008-10-20 20:59:51 +04:00
static size_t gensec_gssapi_sig_size ( struct gensec_security * gensec_security , size_t data_size )
2008-08-06 23:30:17 +04:00
{
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
2015-06-23 13:32:34 +03:00
size_t sig_size ;
2008-08-06 23:30:17 +04:00
2015-06-23 13:32:34 +03:00
if ( gensec_gssapi_state - > sig_size > 0 ) {
2008-08-06 23:30:17 +04:00
return gensec_gssapi_state - > sig_size ;
}
2015-06-23 13:32:34 +03:00
sig_size = gssapi_get_sig_size ( gensec_gssapi_state - > gssapi_context ,
gensec_gssapi_state - > gss_oid ,
2016-09-02 09:20:37 +03:00
gensec_gssapi_state - > gss_got_flags ,
2015-06-23 13:32:34 +03:00
data_size ) ;
2008-08-06 23:30:17 +04:00
2015-06-23 13:32:34 +03:00
gensec_gssapi_state - > sig_size = sig_size ;
2008-08-06 23:30:17 +04:00
return gensec_gssapi_state - > sig_size ;
}
2017-03-01 06:00:03 +03:00
static const char * gensec_gssapi_final_auth_type ( struct gensec_security * gensec_security )
{
struct gensec_gssapi_state * gensec_gssapi_state
= talloc_get_type ( gensec_security - > private_data , struct gensec_gssapi_state ) ;
/* Only return the string for GSSAPI/Krb5 */
if ( smb_gss_oid_equal ( gensec_gssapi_state - > gss_oid ,
gss_mech_krb5 ) ) {
return GENSEC_FINAL_AUTH_TYPE_KRB5 ;
} else {
return " gensec_gssapi: UNKNOWN MECH " ;
}
}
2005-09-24 07:31:01 +04:00
static const char * gensec_gssapi_krb5_oids [ ] = {
2005-05-16 03:42:11 +04:00
GENSEC_OID_KERBEROS5_OLD ,
2006-12-11 19:45:31 +03:00
GENSEC_OID_KERBEROS5 ,
2005-05-16 03:42:11 +04:00
NULL
2005-01-01 03:19:08 +03:00
} ;
2006-11-10 05:44:38 +03:00
static const char * gensec_gssapi_spnego_oids [ ] = {
GENSEC_OID_SPNEGO ,
NULL
} ;
/* As a server, this could in theory accept any GSSAPI mech */
static const struct gensec_security_ops gensec_gssapi_spnego_security_ops = {
. name = " gssapi_spnego " ,
. sasl_name = " GSS-SPNEGO " ,
. auth_type = DCERPC_AUTH_TYPE_SPNEGO ,
. oid = gensec_gssapi_spnego_oids ,
. client_start = gensec_gssapi_client_start ,
. server_start = gensec_gssapi_server_start ,
2012-04-01 05:37:56 +04:00
. magic = gensec_magic_check_krb5_oid ,
2017-05-11 10:04:02 +03:00
. update_send = gensec_gssapi_update_send ,
. update_recv = gensec_gssapi_update_recv ,
2006-11-10 05:44:38 +03:00
. session_key = gensec_gssapi_session_key ,
. session_info = gensec_gssapi_session_info ,
. sign_packet = gensec_gssapi_sign_packet ,
. check_packet = gensec_gssapi_check_packet ,
. seal_packet = gensec_gssapi_seal_packet ,
. unseal_packet = gensec_gssapi_unseal_packet ,
2015-06-19 00:18:58 +03:00
. max_input_size = gensec_gssapi_max_input_size ,
. max_wrapped_size = gensec_gssapi_max_wrapped_size ,
2006-11-10 05:44:38 +03:00
. wrap = gensec_gssapi_wrap ,
. unwrap = gensec_gssapi_unwrap ,
. have_feature = gensec_gssapi_have_feature ,
2012-03-03 07:33:55 +04:00
. expire_time = gensec_gssapi_expire_time ,
2017-03-01 06:00:03 +03:00
. final_auth_type = gensec_gssapi_final_auth_type ,
2007-10-07 02:16:19 +04:00
. enabled = false ,
. kerberos = true ,
2006-11-10 05:44:38 +03:00
. priority = GENSEC_GSSAPI
} ;
2005-05-11 16:11:35 +04:00
/* As a server, this could in theory accept any GSSAPI mech */
2005-05-16 03:42:11 +04:00
static const struct gensec_security_ops gensec_gssapi_krb5_security_ops = {
. name = " gssapi_krb5 " ,
2005-08-23 20:13:39 +04:00
. auth_type = DCERPC_AUTH_TYPE_KRB5 ,
2005-09-24 07:31:01 +04:00
. oid = gensec_gssapi_krb5_oids ,
2005-05-11 16:11:35 +04:00
. client_start = gensec_gssapi_client_start ,
. server_start = gensec_gssapi_server_start ,
2012-04-01 05:37:56 +04:00
. magic = gensec_magic_check_krb5_oid ,
2017-05-11 10:04:02 +03:00
. update_send = gensec_gssapi_update_send ,
. update_recv = gensec_gssapi_update_recv ,
2005-05-11 16:11:35 +04:00
. session_key = gensec_gssapi_session_key ,
. session_info = gensec_gssapi_session_info ,
2008-08-06 23:30:17 +04:00
. sig_size = gensec_gssapi_sig_size ,
2005-05-11 16:11:35 +04:00
. sign_packet = gensec_gssapi_sign_packet ,
. check_packet = gensec_gssapi_check_packet ,
. seal_packet = gensec_gssapi_seal_packet ,
. unseal_packet = gensec_gssapi_unseal_packet ,
2015-06-19 00:18:58 +03:00
. max_input_size = gensec_gssapi_max_input_size ,
. max_wrapped_size = gensec_gssapi_max_wrapped_size ,
2005-05-11 16:11:35 +04:00
. wrap = gensec_gssapi_wrap ,
. unwrap = gensec_gssapi_unwrap ,
. have_feature = gensec_gssapi_have_feature ,
2012-03-03 07:33:55 +04:00
. expire_time = gensec_gssapi_expire_time ,
2017-03-01 06:00:03 +03:00
. final_auth_type = gensec_gssapi_final_auth_type ,
2007-10-07 02:16:19 +04:00
. enabled = true ,
. kerberos = true ,
2006-09-08 10:21:02 +04:00
. priority = GENSEC_GSSAPI
2005-01-03 02:53:14 +03:00
} ;
2006-02-04 12:53:50 +03:00
/* As a server, this could in theory accept any GSSAPI mech */
static const struct gensec_security_ops gensec_gssapi_sasl_krb5_security_ops = {
2006-07-21 05:44:24 +04:00
. name = " gssapi_krb5_sasl " ,
. sasl_name = " GSSAPI " ,
. client_start = gensec_gssapi_sasl_client_start ,
. server_start = gensec_gssapi_sasl_server_start ,
2017-05-11 10:04:02 +03:00
. update_send = gensec_gssapi_update_send ,
. update_recv = gensec_gssapi_update_recv ,
2006-07-21 05:44:24 +04:00
. session_key = gensec_gssapi_session_key ,
. session_info = gensec_gssapi_session_info ,
. max_input_size = gensec_gssapi_max_input_size ,
. max_wrapped_size = gensec_gssapi_max_wrapped_size ,
. wrap = gensec_gssapi_wrap ,
. unwrap = gensec_gssapi_unwrap ,
. have_feature = gensec_gssapi_have_feature ,
2012-03-03 07:33:55 +04:00
. expire_time = gensec_gssapi_expire_time ,
2017-03-01 06:00:03 +03:00
. final_auth_type = gensec_gssapi_final_auth_type ,
2007-10-07 02:16:19 +04:00
. enabled = true ,
. kerberos = true ,
2006-09-08 10:21:02 +04:00
. priority = GENSEC_GSSAPI
2006-02-04 12:53:50 +03:00
} ;
2017-04-20 22:24:43 +03:00
_PUBLIC_ NTSTATUS gensec_gssapi_init ( TALLOC_CTX * ctx )
2005-01-01 03:19:08 +03:00
{
NTSTATUS ret ;
2017-05-12 01:56:29 +03:00
ret = gensec_register ( ctx , & gensec_gssapi_spnego_security_ops ) ;
2006-11-10 05:44:38 +03:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
DEBUG ( 0 , ( " Failed to register '%s' gensec backend! \n " ,
gensec_gssapi_spnego_security_ops . name ) ) ;
return ret ;
}
2017-05-12 01:56:29 +03:00
ret = gensec_register ( ctx , & gensec_gssapi_krb5_security_ops ) ;
2005-01-03 02:53:14 +03:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
DEBUG ( 0 , ( " Failed to register '%s' gensec backend! \n " ,
gensec_gssapi_krb5_security_ops . name ) ) ;
return ret ;
}
2017-05-12 01:56:29 +03:00
ret = gensec_register ( ctx , & gensec_gssapi_sasl_krb5_security_ops ) ;
2006-02-04 12:53:50 +03:00
if ( ! NT_STATUS_IS_OK ( ret ) ) {
DEBUG ( 0 , ( " Failed to register '%s' gensec backend! \n " ,
gensec_gssapi_sasl_krb5_security_ops . name ) ) ;
return ret ;
}
2005-01-01 03:19:08 +03:00
return ret ;
}