2005-07-11 05:16:55 +04:00
/*
2008-10-27 13:35:07 +03:00
* Copyright ( c ) 1997 - 2007 Kungliga Tekniska Högskolan
* ( Royal Institute of Technology , Stockholm , Sweden ) .
* All rights reserved .
2005-07-11 05:16:55 +04:00
*
2010-01-12 10:16:45 +03:00
* Portions Copyright ( c ) 2009 Apple Inc . All rights reserved .
*
2008-10-27 13:35:07 +03:00
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
2005-07-11 05:16:55 +04:00
*
2008-10-27 13:35:07 +03:00
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
2005-07-11 05:16:55 +04:00
*
2008-10-27 13:35:07 +03:00
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
2005-07-11 05:16:55 +04:00
*
2008-10-27 13:35:07 +03:00
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission .
2007-01-24 05:48:40 +03:00
*
2008-10-27 13:35:07 +03:00
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ` ` AS IS ' ' AND
* ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
* DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT
* LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE .
2005-07-11 05:16:55 +04:00
*/
# include "kdc_locl.h"
2007-06-13 09:44:24 +04:00
# include <getarg.h>
# include <parse_bytes.h>
2005-07-11 05:16:55 +04:00
2007-07-03 12:00:08 +04:00
krb5_error_code
2007-06-13 09:44:24 +04:00
krb5_kdc_get_config ( krb5_context context , krb5_kdc_configuration * * config )
2007-01-24 05:48:40 +03:00
{
2007-06-13 09:44:24 +04:00
krb5_kdc_configuration * c ;
2007-01-24 05:48:40 +03:00
2007-06-13 09:44:24 +04:00
c = calloc ( 1 , sizeof ( * c ) ) ;
if ( c = = NULL ) {
2008-08-01 09:08:51 +04:00
krb5_set_error_message ( context , ENOMEM , " malloc: out of memory " ) ;
2007-06-13 09:44:24 +04:00
return ENOMEM ;
2007-01-24 05:48:40 +03:00
}
2007-06-13 09:44:24 +04:00
c - > require_preauth = TRUE ;
c - > kdc_warn_pwexpire = 0 ;
c - > encode_as_rep_as_tgs_rep = FALSE ;
2011-07-15 11:10:30 +04:00
c - > as_use_strongest_session_key = FALSE ;
c - > preauth_use_strongest_session_key = FALSE ;
c - > tgs_use_strongest_session_key = FALSE ;
2011-07-25 20:51:53 +04:00
c - > use_strongest_server_key = TRUE ;
2007-06-13 09:44:24 +04:00
c - > check_ticket_addresses = TRUE ;
c - > allow_null_ticket_addresses = TRUE ;
c - > allow_anonymous = FALSE ;
c - > trpolicy = TRPOLICY_ALWAYS_CHECK ;
c - > enable_pkinit = FALSE ;
2007-07-03 12:00:08 +04:00
c - > pkinit_princ_in_cert = TRUE ;
c - > pkinit_require_binding = TRUE ;
2007-06-13 09:44:24 +04:00
c - > db = NULL ;
c - > num_db = 0 ;
c - > logf = NULL ;
c - > require_preauth =
2008-10-27 13:35:07 +03:00
krb5_config_get_bool_default ( context , NULL ,
2007-06-13 09:44:24 +04:00
c - > require_preauth ,
" kdc " , " require-preauth " , NULL ) ;
2009-06-08 13:06:16 +04:00
# ifdef DIGEST
2008-10-27 13:35:07 +03:00
c - > enable_digest =
krb5_config_get_bool_default ( context , NULL ,
2007-06-13 09:44:24 +04:00
FALSE ,
" kdc " , " enable-digest " , NULL ) ;
2007-01-24 05:48:40 +03:00
{
const char * digests ;
2008-10-27 13:35:07 +03:00
digests = krb5_config_get_string ( context , NULL ,
" kdc " ,
2007-01-24 05:48:40 +03:00
" digests_allowed " , NULL ) ;
if ( digests = = NULL )
digests = " ntlm-v2 " ;
2007-06-13 09:44:24 +04:00
c - > digests_allowed = parse_flags ( digests , _kdc_digestunits , 0 ) ;
if ( c - > digests_allowed = = - 1 ) {
kdc_log ( context , c , 0 ,
2007-01-24 05:48:40 +03:00
" unparsable digest units (%s), turning off digest " ,
digests ) ;
2007-06-13 09:44:24 +04:00
c - > enable_digest = 0 ;
} else if ( c - > digests_allowed = = 0 ) {
kdc_log ( context , c , 0 ,
2007-01-24 05:48:40 +03:00
" no digest enable, turning digest off " ,
digests ) ;
2007-06-13 09:44:24 +04:00
c - > enable_digest = 0 ;
2007-01-24 05:48:40 +03:00
}
}
2009-06-08 13:06:16 +04:00
# endif
2007-01-24 05:48:40 +03:00
2009-06-08 13:06:16 +04:00
# ifdef KX509
2008-10-27 13:35:07 +03:00
c - > enable_kx509 =
krb5_config_get_bool_default ( context , NULL ,
FALSE ,
2007-06-13 09:44:24 +04:00
" kdc " , " enable-kx509 " , NULL ) ;
if ( c - > enable_kx509 ) {
c - > kx509_template =
2008-10-27 13:35:07 +03:00
krb5_config_get_string ( context , NULL ,
2007-06-13 09:44:24 +04:00
" kdc " , " kx509_template " , NULL ) ;
c - > kx509_ca =
2008-10-27 13:35:07 +03:00
krb5_config_get_string ( context , NULL ,
2007-06-13 09:44:24 +04:00
" kdc " , " kx509_ca " , NULL ) ;
if ( c - > kx509_ca = = NULL | | c - > kx509_template = = NULL ) {
kdc_log ( context , c , 0 ,
" missing kx509 configuration, turning off " ) ;
c - > enable_kx509 = FALSE ;
}
}
2009-06-08 13:06:16 +04:00
# endif
2007-01-24 05:48:40 +03:00
2011-07-15 11:10:30 +04:00
c - > as_use_strongest_session_key =
krb5_config_get_bool_default ( context , NULL ,
c - > as_use_strongest_session_key ,
" kdc " ,
" as-use-strongest-session-key " , NULL ) ;
c - > preauth_use_strongest_session_key =
krb5_config_get_bool_default ( context , NULL ,
c - > preauth_use_strongest_session_key ,
" kdc " ,
" preauth-use-strongest-session-key " , NULL ) ;
c - > tgs_use_strongest_session_key =
krb5_config_get_bool_default ( context , NULL ,
c - > tgs_use_strongest_session_key ,
" kdc " ,
" tgs-use-strongest-session-key " , NULL ) ;
c - > use_strongest_server_key =
krb5_config_get_bool_default ( context , NULL ,
c - > use_strongest_server_key ,
" kdc " ,
" use-strongest-server-key " , NULL ) ;
2008-10-27 13:35:07 +03:00
c - > check_ticket_addresses =
krb5_config_get_bool_default ( context , NULL ,
c - > check_ticket_addresses ,
" kdc " ,
2007-01-24 05:48:40 +03:00
" check-ticket-addresses " , NULL ) ;
2008-10-27 13:35:07 +03:00
c - > allow_null_ticket_addresses =
krb5_config_get_bool_default ( context , NULL ,
c - > allow_null_ticket_addresses ,
" kdc " ,
2007-01-24 05:48:40 +03:00
" allow-null-ticket-addresses " , NULL ) ;
2008-10-27 13:35:07 +03:00
c - > allow_anonymous =
krb5_config_get_bool_default ( context , NULL ,
2007-06-13 09:44:24 +04:00
c - > allow_anonymous ,
2008-10-27 13:35:07 +03:00
" kdc " ,
2007-01-24 05:48:40 +03:00
" allow-anonymous " , NULL ) ;
2007-06-13 09:44:24 +04:00
c - > max_datagram_reply_length =
2008-10-27 13:35:07 +03:00
krb5_config_get_int_default ( context ,
NULL ,
2007-01-24 05:48:40 +03:00
1400 ,
" kdc " ,
" max-kdc-datagram-reply-length " ,
NULL ) ;
2007-06-13 09:44:24 +04:00
{
const char * trpolicy_str ;
2008-10-27 13:35:07 +03:00
trpolicy_str =
krb5_config_get_string_default ( context , NULL , " DEFAULT " , " kdc " ,
2007-06-13 09:44:24 +04:00
" transited-policy " , NULL ) ;
if ( strcasecmp ( trpolicy_str , " always-check " ) = = 0 ) {
c - > trpolicy = TRPOLICY_ALWAYS_CHECK ;
} else if ( strcasecmp ( trpolicy_str , " allow-per-principal " ) = = 0 ) {
c - > trpolicy = TRPOLICY_ALLOW_PER_PRINCIPAL ;
} else if ( strcasecmp ( trpolicy_str , " always-honour-request " ) = = 0 ) {
c - > trpolicy = TRPOLICY_ALWAYS_HONOUR_REQUEST ;
2008-10-27 13:35:07 +03:00
} else if ( strcasecmp ( trpolicy_str , " DEFAULT " ) = = 0 ) {
2007-06-13 09:44:24 +04:00
/* default */
} else {
kdc_log ( context , c , 0 ,
" unknown transited-policy: %s, "
2008-10-27 13:35:07 +03:00
" reverting to default (always-check) " ,
2007-06-13 09:44:24 +04:00
trpolicy_str ) ;
}
2007-01-24 05:48:40 +03:00
}
2007-06-13 09:44:24 +04:00
c - > encode_as_rep_as_tgs_rep =
2008-10-27 13:35:07 +03:00
krb5_config_get_bool_default ( context , NULL ,
c - > encode_as_rep_as_tgs_rep ,
" kdc " ,
2007-06-13 09:44:24 +04:00
" encode_as_rep_as_tgs_rep " , NULL ) ;
2008-10-27 13:35:07 +03:00
2007-06-13 09:44:24 +04:00
c - > kdc_warn_pwexpire =
2007-01-24 05:48:40 +03:00
krb5_config_get_time_default ( context , NULL ,
2007-06-13 09:44:24 +04:00
c - > kdc_warn_pwexpire ,
" kdc " , " kdc_warn_pwexpire " , NULL ) ;
2007-01-24 05:48:40 +03:00
2008-10-27 13:35:07 +03:00
c - > enable_pkinit =
krb5_config_get_bool_default ( context ,
NULL ,
2007-06-13 09:44:24 +04:00
c - > enable_pkinit ,
2007-01-24 05:48:40 +03:00
" kdc " ,
" enable-pkinit " ,
NULL ) ;
2011-07-15 11:10:30 +04:00
c - > pkinit_kdc_identity =
2010-01-12 10:16:45 +03:00
krb5_config_get_string ( context , NULL ,
" kdc " , " pkinit_identity " , NULL ) ;
c - > pkinit_kdc_anchors =
krb5_config_get_string ( context , NULL ,
" kdc " , " pkinit_anchors " , NULL ) ;
c - > pkinit_kdc_cert_pool =
krb5_config_get_strings ( context , NULL ,
" kdc " , " pkinit_pool " , NULL ) ;
c - > pkinit_kdc_revoke =
krb5_config_get_strings ( context , NULL ,
" kdc " , " pkinit_revoke " , NULL ) ;
2011-07-15 11:10:30 +04:00
c - > pkinit_kdc_ocsp_file =
2010-01-12 10:16:45 +03:00
krb5_config_get_string ( context , NULL ,
" kdc " , " pkinit_kdc_ocsp " , NULL ) ;
c - > pkinit_kdc_friendly_name =
krb5_config_get_string ( context , NULL ,
" kdc " , " pkinit_kdc_friendly_name " , NULL ) ;
c - > pkinit_princ_in_cert =
krb5_config_get_bool_default ( context , NULL ,
c - > pkinit_princ_in_cert ,
" kdc " ,
" pkinit_principal_in_certificate " ,
NULL ) ;
c - > pkinit_require_binding =
krb5_config_get_bool_default ( context , NULL ,
c - > pkinit_require_binding ,
" kdc " ,
" pkinit_win2k_require_binding " ,
NULL ) ;
c - > pkinit_dh_min_bits =
krb5_config_get_int_default ( context , NULL ,
0 ,
" kdc " , " pkinit_dh_min_bits " , NULL ) ;
2007-01-24 05:48:40 +03:00
2010-11-11 03:27:33 +03:00
* config = c ;
2007-01-24 05:48:40 +03:00
2010-11-11 03:27:33 +03:00
return 0 ;
}
krb5_error_code
krb5_kdc_pkinit_config ( krb5_context context , krb5_kdc_configuration * config )
{
# ifdef PKINIT
2010-01-12 10:16:45 +03:00
# ifdef __APPLE__
2010-11-11 03:27:33 +03:00
config - > enable_pkinit = 1 ;
2009-06-08 13:06:16 +04:00
2010-11-11 03:27:33 +03:00
if ( config - > pkinit_kdc_identity = = NULL ) {
if ( config - > pkinit_kdc_friendly_name = = NULL )
2011-07-15 11:10:30 +04:00
config - > pkinit_kdc_friendly_name =
2010-01-12 10:16:45 +03:00
strdup ( " O=System Identity,CN=com.apple.kerberos.kdc " ) ;
2010-11-11 03:27:33 +03:00
config - > pkinit_kdc_identity = strdup ( " KEYCHAIN: " ) ;
2010-01-12 10:16:45 +03:00
}
2010-11-11 03:27:33 +03:00
if ( config - > pkinit_kdc_anchors = = NULL )
config - > pkinit_kdc_anchors = strdup ( " KEYCHAIN: " ) ;
2009-06-08 13:06:16 +04:00
2010-11-11 03:27:33 +03:00
# endif /* __APPLE__ */
2007-01-24 05:48:40 +03:00
2010-11-11 03:27:33 +03:00
if ( config - > enable_pkinit ) {
if ( config - > pkinit_kdc_identity = = NULL )
2010-01-12 10:16:45 +03:00
krb5_errx ( context , 1 , " pkinit enabled but no identity " ) ;
2011-07-15 11:10:30 +04:00
2010-11-11 03:27:33 +03:00
if ( config - > pkinit_kdc_anchors = = NULL )
2010-01-12 10:16:45 +03:00
krb5_errx ( context , 1 , " pkinit enabled but no X509 anchors " ) ;
2007-01-24 05:48:40 +03:00
2010-11-11 03:27:33 +03:00
krb5_kdc_pk_initialize ( context , config ,
config - > pkinit_kdc_identity ,
config - > pkinit_kdc_anchors ,
config - > pkinit_kdc_cert_pool ,
config - > pkinit_kdc_revoke ) ;
2007-07-03 12:00:08 +04:00
2007-01-24 05:48:40 +03:00
}
2010-08-15 18:31:28 +04:00
2010-11-16 00:42:22 +03:00
return 0 ;
2010-11-29 03:24:08 +03:00
# endif /* PKINIT */
2011-07-15 11:10:30 +04:00
}