2004-06-19 12:15:41 +04:00
/*
Unix SMB / CIFS implementation .
simple kerberos5 routines for active directory
Copyright ( C ) Andrew Tridgell 2001
Copyright ( C ) Luke Howard 2002 - 2003
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
2004-06-19 12:15:41 +04: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/>.
2004-06-19 12:15:41 +04:00
*/
# if defined(HAVE_KRB5)
2005-09-17 05:11:50 +04:00
# include "auth/kerberos/krb5_init_context.h"
2006-03-14 18:03:25 +03:00
# include "librpc/gen_ndr/krb5pac.h"
struct auth_serversupplied_info ;
2006-11-07 03:48:36 +03:00
struct cli_credentials ;
2005-06-05 02:27:33 +04:00
2005-08-29 08:30:22 +04:00
struct ccache_container {
struct smb_krb5_context * smb_krb5_context ;
krb5_ccache ccache ;
} ;
2005-06-04 15:17:05 +04:00
2005-10-20 07:47:55 +04:00
struct keytab_container {
struct smb_krb5_context * smb_krb5_context ;
krb5_keytab keytab ;
} ;
2004-12-05 19:29:27 +03:00
/* not really ASN.1, but RFC 1964 */
2005-10-30 13:39:52 +03:00
# define TOK_ID_KRB_AP_REQ ((const uint8_t *)"\x01\x00")
# define TOK_ID_KRB_AP_REP ((const uint8_t *)"\x02\x00")
# define TOK_ID_KRB_ERROR ((const uint8_t *)"\x03\x00")
# define TOK_ID_GSS_GETMIC ((const uint8_t *)"\x01\x01")
# define TOK_ID_GSS_WRAP ((const uint8_t *)"\x02\x01")
2004-12-05 19:29:27 +03:00
2004-07-11 14:47:41 +04:00
# ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE
# define KRB5_KEY_TYPE(k) ((k)->keytype)
# define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length)
# define KRB5_KEY_DATA(k) ((k)->keyvalue.data)
# else
# define KRB5_KEY_TYPE(k) ((k)->enctype)
# define KRB5_KEY_LENGTH(k) ((k)->length)
# define KRB5_KEY_DATA(k) ((k)->contents)
# endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */
2004-06-19 12:15:41 +04:00
# ifndef HAVE_KRB5_SET_REAL_TIME
krb5_error_code krb5_set_real_time ( krb5_context context , int32_t seconds , int32_t microseconds ) ;
# endif
# ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
krb5_error_code krb5_set_default_tgs_ktypes ( krb5_context ctx , const krb5_enctype * enc ) ;
# endif
# if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
krb5_error_code krb5_auth_con_setuseruserkey ( krb5_context context , krb5_auth_context auth_context , krb5_keyblock * keyblock ) ;
# endif
# ifndef HAVE_KRB5_FREE_UNPARSED_NAME
void krb5_free_unparsed_name ( krb5_context ctx , char * val ) ;
# endif
2004-08-12 11:37:49 +04:00
# if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT)
const krb5_data * krb5_princ_component ( krb5_context context , krb5_principal principal , int i ) ;
# endif
2004-06-19 12:15:41 +04:00
/* Samba wrapper function for krb5 functionality. */
void setup_kaddr ( krb5_address * pkaddr , struct sockaddr * paddr ) ;
int create_kerberos_key_from_string ( krb5_context context , krb5_principal host_princ , krb5_data * password , krb5_keyblock * key , krb5_enctype enctype ) ;
2004-12-24 12:54:23 +03:00
int create_kerberos_key_from_string_direct ( krb5_context context , krb5_principal host_princ , krb5_data * password , krb5_keyblock * key , krb5_enctype enctype ) ;
2004-06-19 12:15:41 +04:00
krb5_const_principal get_principal_from_tkt ( krb5_ticket * tkt ) ;
krb5_error_code get_kerberos_allowed_etypes ( krb5_context context , krb5_enctype * * enctypes ) ;
void free_kerberos_etypes ( krb5_context context , krb5_enctype * enctypes ) ;
2007-08-27 22:10:19 +04:00
bool get_krb5_smb_session_key ( krb5_context context , krb5_auth_context auth_context , DATA_BLOB * session_key , bool remote ) ;
2004-07-11 14:47:41 +04:00
krb5_error_code ads_krb5_mk_req ( krb5_context context ,
krb5_auth_context * auth_context ,
const krb5_flags ap_req_options ,
const char * principal ,
krb5_ccache ccache ,
krb5_data * outbuf ) ;
2007-08-27 22:10:19 +04:00
bool get_auth_data_from_tkt ( TALLOC_CTX * mem_ctx , DATA_BLOB * auth_data , krb5_ticket * tkt ) ;
2004-12-24 12:54:23 +03:00
int kerberos_kinit_password_cc ( krb5_context ctx , krb5_ccache cc ,
2005-09-05 14:53:14 +04:00
krb5_principal principal , const char * password ,
2004-12-24 12:54:23 +03:00
time_t * expire_time , time_t * kdc_time ) ;
2005-06-28 12:27:50 +04:00
int kerberos_kinit_keyblock_cc ( krb5_context ctx , krb5_ccache cc ,
2005-09-05 14:53:14 +04:00
krb5_principal principal , krb5_keyblock * keyblock ,
2005-06-28 12:27:50 +04:00
time_t * expire_time , time_t * kdc_time ) ;
2004-12-24 12:54:23 +03:00
krb5_principal kerberos_fetch_salt_princ_for_host_princ ( krb5_context context ,
krb5_principal host_princ ,
int enctype ) ;
void kerberos_set_creds_enctype ( krb5_creds * pcreds , int enctype ) ;
2007-08-27 22:10:19 +04:00
bool kerberos_compatible_enctypes ( krb5_context context , krb5_enctype enctype1 , krb5_enctype enctype2 ) ;
2004-12-24 12:54:23 +03:00
void kerberos_free_data_contents ( krb5_context context , krb5_data * pdata ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
krb5_error_code smb_krb5_kt_free_entry ( krb5_context context , krb5_keytab_entry * kt_entry ) ;
2005-03-28 10:40:18 +04:00
char * smb_get_krb5_error_message ( krb5_context context , krb5_error_code code , TALLOC_CTX * mem_ctx ) ;
2005-08-29 08:30:22 +04:00
krb5_error_code kinit_to_ccache ( TALLOC_CTX * parent_ctx ,
2005-06-04 15:17:05 +04:00
struct cli_credentials * credentials ,
struct smb_krb5_context * smb_krb5_context ,
2005-08-29 08:30:22 +04:00
krb5_ccache ccache ) ;
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
krb5_error_code principal_from_credentials ( TALLOC_CTX * parent_ctx ,
struct cli_credentials * credentials ,
struct smb_krb5_context * smb_krb5_context ,
krb5_principal * princ ) ;
2005-06-28 12:27:50 +04:00
NTSTATUS kerberos_decode_pac ( TALLOC_CTX * mem_ctx ,
2008-02-21 16:16:02 +03:00
struct smb_iconv_convenience * iconv_convenience ,
2005-08-05 04:41:53 +04:00
struct PAC_DATA * * pac_data_out ,
2005-06-28 12:27:50 +04:00
DATA_BLOB blob ,
2005-08-27 16:23:37 +04:00
krb5_context context ,
2006-11-11 18:11:21 +03:00
const krb5_keyblock * krbtgt_keyblock ,
const krb5_keyblock * service_keyblock ,
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
krb5_const_principal client_principal ,
2005-11-07 05:29:37 +03:00
time_t tgs_authtime ,
krb5_error_code * k5ret ) ;
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
NTSTATUS kerberos_pac_logon_info ( TALLOC_CTX * mem_ctx ,
2008-02-21 16:16:02 +03:00
struct smb_iconv_convenience * iconv_convenience ,
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
struct PAC_LOGON_INFO * * logon_info ,
DATA_BLOB blob ,
krb5_context context ,
2006-11-11 18:11:21 +03:00
const krb5_keyblock * krbtgt_keyblock ,
const krb5_keyblock * service_keyblock ,
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
krb5_const_principal client_principal ,
2005-11-07 05:29:37 +03:00
time_t tgs_authtime ,
krb5_error_code * k5ret ) ;
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
krb5_error_code kerberos_encode_pac ( TALLOC_CTX * mem_ctx ,
2008-02-21 16:16:02 +03:00
struct smb_iconv_convenience * iconv_convenience ,
2005-08-05 04:41:53 +04:00
struct PAC_DATA * pac_data ,
krb5_context context ,
2006-11-11 18:11:21 +03:00
const krb5_keyblock * krbtgt_keyblock ,
const krb5_keyblock * service_keyblock ,
DATA_BLOB * pac ) ;
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
krb5_error_code kerberos_create_pac ( TALLOC_CTX * mem_ctx ,
2008-02-21 16:16:02 +03:00
struct smb_iconv_convenience * iconv_convenience ,
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
struct auth_serversupplied_info * server_info ,
krb5_context context ,
2006-11-11 18:11:21 +03:00
const krb5_keyblock * krbtgt_keyblock ,
const krb5_keyblock * service_keyblock ,
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
krb5_principal client_principal ,
time_t tgs_authtime ,
DATA_BLOB * pac ) ;
2007-12-02 22:56:26 +03:00
struct loadparm_context ;
2005-11-02 03:31:22 +03:00
2006-03-07 15:08:58 +03:00
# include "auth/kerberos/proto.h"
2004-06-19 12:15:41 +04:00
# endif /* HAVE_KRB5 */