Path: blob/main/crypto/heimdal/kdc/default_config.c
34859 views
/*1* Copyright (c) 1997-2007 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "kdc_locl.h"36#include <getarg.h>37#include <parse_bytes.h>3839krb5_error_code40krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config)41{42krb5_kdc_configuration *c;4344c = calloc(1, sizeof(*c));45if (c == NULL) {46krb5_set_error_message(context, ENOMEM, "malloc: out of memory");47return ENOMEM;48}4950c->require_preauth = TRUE;51c->kdc_warn_pwexpire = 0;52c->encode_as_rep_as_tgs_rep = FALSE;53c->tgt_use_strongest_session_key = FALSE;54c->preauth_use_strongest_session_key = FALSE;55c->svc_use_strongest_session_key = FALSE;56c->use_strongest_server_key = TRUE;57c->check_ticket_addresses = TRUE;58c->allow_null_ticket_addresses = TRUE;59c->allow_anonymous = FALSE;60c->trpolicy = TRPOLICY_ALWAYS_CHECK;61c->enable_pkinit = FALSE;62c->pkinit_princ_in_cert = TRUE;63c->pkinit_require_binding = TRUE;64c->db = NULL;65c->num_db = 0;66c->logf = NULL;6768c->require_preauth =69krb5_config_get_bool_default(context, NULL,70c->require_preauth,71"kdc", "require-preauth", NULL);72#ifdef DIGEST73c->enable_digest =74krb5_config_get_bool_default(context, NULL,75FALSE,76"kdc", "enable-digest", NULL);7778{79const char *digests;8081digests = krb5_config_get_string(context, NULL,82"kdc",83"digests_allowed", NULL);84if (digests == NULL)85digests = "ntlm-v2";86c->digests_allowed = parse_flags(digests,_kdc_digestunits, 0);87if (c->digests_allowed == -1) {88kdc_log(context, c, 0,89"unparsable digest units (%s), turning off digest",90digests);91c->enable_digest = 0;92} else if (c->digests_allowed == 0) {93kdc_log(context, c, 0,94"no digest enable, turning digest off",95digests);96c->enable_digest = 0;97}98}99#endif100101#ifdef KX509102c->enable_kx509 =103krb5_config_get_bool_default(context, NULL,104FALSE,105"kdc", "enable-kx509", NULL);106107if (c->enable_kx509) {108c->kx509_template =109krb5_config_get_string(context, NULL,110"kdc", "kx509_template", NULL);111c->kx509_ca =112krb5_config_get_string(context, NULL,113"kdc", "kx509_ca", NULL);114if (c->kx509_ca == NULL || c->kx509_template == NULL) {115kdc_log(context, c, 0,116"missing kx509 configuration, turning off");117c->enable_kx509 = FALSE;118}119}120#endif121122c->tgt_use_strongest_session_key =123krb5_config_get_bool_default(context, NULL,124c->tgt_use_strongest_session_key,125"kdc",126"tgt-use-strongest-session-key", NULL);127c->preauth_use_strongest_session_key =128krb5_config_get_bool_default(context, NULL,129c->preauth_use_strongest_session_key,130"kdc",131"preauth-use-strongest-session-key", NULL);132c->svc_use_strongest_session_key =133krb5_config_get_bool_default(context, NULL,134c->svc_use_strongest_session_key,135"kdc",136"svc-use-strongest-session-key", NULL);137c->use_strongest_server_key =138krb5_config_get_bool_default(context, NULL,139c->use_strongest_server_key,140"kdc",141"use-strongest-server-key", NULL);142143c->check_ticket_addresses =144krb5_config_get_bool_default(context, NULL,145c->check_ticket_addresses,146"kdc",147"check-ticket-addresses", NULL);148c->allow_null_ticket_addresses =149krb5_config_get_bool_default(context, NULL,150c->allow_null_ticket_addresses,151"kdc",152"allow-null-ticket-addresses", NULL);153154c->allow_anonymous =155krb5_config_get_bool_default(context, NULL,156c->allow_anonymous,157"kdc",158"allow-anonymous", NULL);159160c->max_datagram_reply_length =161krb5_config_get_int_default(context,162NULL,1631400,164"kdc",165"max-kdc-datagram-reply-length",166NULL);167168{169const char *trpolicy_str;170171trpolicy_str =172krb5_config_get_string_default(context, NULL, "DEFAULT", "kdc",173"transited-policy", NULL);174if(strcasecmp(trpolicy_str, "always-check") == 0) {175c->trpolicy = TRPOLICY_ALWAYS_CHECK;176} else if(strcasecmp(trpolicy_str, "allow-per-principal") == 0) {177c->trpolicy = TRPOLICY_ALLOW_PER_PRINCIPAL;178} else if(strcasecmp(trpolicy_str, "always-honour-request") == 0) {179c->trpolicy = TRPOLICY_ALWAYS_HONOUR_REQUEST;180} else if(strcasecmp(trpolicy_str, "DEFAULT") == 0) {181/* default */182} else {183kdc_log(context, c, 0,184"unknown transited-policy: %s, "185"reverting to default (always-check)",186trpolicy_str);187}188}189190c->encode_as_rep_as_tgs_rep =191krb5_config_get_bool_default(context, NULL,192c->encode_as_rep_as_tgs_rep,193"kdc",194"encode_as_rep_as_tgs_rep", NULL);195196c->kdc_warn_pwexpire =197krb5_config_get_time_default (context, NULL,198c->kdc_warn_pwexpire,199"kdc", "kdc_warn_pwexpire", NULL);200201202c->enable_pkinit =203krb5_config_get_bool_default(context,204NULL,205c->enable_pkinit,206"kdc",207"enable-pkinit",208NULL);209210211c->pkinit_kdc_identity =212krb5_config_get_string(context, NULL,213"kdc", "pkinit_identity", NULL);214c->pkinit_kdc_anchors =215krb5_config_get_string(context, NULL,216"kdc", "pkinit_anchors", NULL);217c->pkinit_kdc_cert_pool =218krb5_config_get_strings(context, NULL,219"kdc", "pkinit_pool", NULL);220c->pkinit_kdc_revoke =221krb5_config_get_strings(context, NULL,222"kdc", "pkinit_revoke", NULL);223c->pkinit_kdc_ocsp_file =224krb5_config_get_string(context, NULL,225"kdc", "pkinit_kdc_ocsp", NULL);226c->pkinit_kdc_friendly_name =227krb5_config_get_string(context, NULL,228"kdc", "pkinit_kdc_friendly_name", NULL);229c->pkinit_princ_in_cert =230krb5_config_get_bool_default(context, NULL,231c->pkinit_princ_in_cert,232"kdc",233"pkinit_principal_in_certificate",234NULL);235c->pkinit_require_binding =236krb5_config_get_bool_default(context, NULL,237c->pkinit_require_binding,238"kdc",239"pkinit_win2k_require_binding",240NULL);241c->pkinit_dh_min_bits =242krb5_config_get_int_default(context, NULL,2430,244"kdc", "pkinit_dh_min_bits", NULL);245246*config = c;247248return 0;249}250251krb5_error_code252krb5_kdc_pkinit_config(krb5_context context, krb5_kdc_configuration *config)253{254#ifdef PKINIT255#ifdef __APPLE__256config->enable_pkinit = 1;257258if (config->pkinit_kdc_identity == NULL) {259if (config->pkinit_kdc_friendly_name == NULL)260config->pkinit_kdc_friendly_name =261strdup("O=System Identity,CN=com.apple.kerberos.kdc");262config->pkinit_kdc_identity = strdup("KEYCHAIN:");263}264if (config->pkinit_kdc_anchors == NULL)265config->pkinit_kdc_anchors = strdup("KEYCHAIN:");266267#endif /* __APPLE__ */268269if (config->enable_pkinit) {270if (config->pkinit_kdc_identity == NULL)271krb5_errx(context, 1, "pkinit enabled but no identity");272273if (config->pkinit_kdc_anchors == NULL)274krb5_errx(context, 1, "pkinit enabled but no X509 anchors");275276krb5_kdc_pk_initialize(context, config,277config->pkinit_kdc_identity,278config->pkinit_kdc_anchors,279config->pkinit_kdc_cert_pool,280config->pkinit_kdc_revoke);281282}283284return 0;285#endif /* PKINIT */286}287288289