1*0a6a1f1dSLionel Sambuc /* $NetBSD: default_config.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $ */
2ebfedea0SLionel Sambuc
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc * All rights reserved.
7ebfedea0SLionel Sambuc *
8ebfedea0SLionel Sambuc * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
9ebfedea0SLionel Sambuc *
10ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
11ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
12ebfedea0SLionel Sambuc * are met:
13ebfedea0SLionel Sambuc *
14ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
15ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
16ebfedea0SLionel Sambuc *
17ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
18ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
19ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
20ebfedea0SLionel Sambuc *
21ebfedea0SLionel Sambuc * 3. Neither the name of the Institute nor the names of its contributors
22ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software
23ebfedea0SLionel Sambuc * without specific prior written permission.
24ebfedea0SLionel Sambuc *
25ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35ebfedea0SLionel Sambuc * SUCH DAMAGE.
36ebfedea0SLionel Sambuc */
37ebfedea0SLionel Sambuc
38ebfedea0SLionel Sambuc #include "kdc_locl.h"
39ebfedea0SLionel Sambuc #include <krb5/getarg.h>
40ebfedea0SLionel Sambuc #include <krb5/parse_bytes.h>
41ebfedea0SLionel Sambuc
42ebfedea0SLionel Sambuc krb5_error_code
krb5_kdc_get_config(krb5_context context,krb5_kdc_configuration ** config)43ebfedea0SLionel Sambuc krb5_kdc_get_config(krb5_context context, krb5_kdc_configuration **config)
44ebfedea0SLionel Sambuc {
45ebfedea0SLionel Sambuc krb5_kdc_configuration *c;
46ebfedea0SLionel Sambuc
47ebfedea0SLionel Sambuc c = calloc(1, sizeof(*c));
48ebfedea0SLionel Sambuc if (c == NULL) {
49ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
50ebfedea0SLionel Sambuc return ENOMEM;
51ebfedea0SLionel Sambuc }
52ebfedea0SLionel Sambuc
53ebfedea0SLionel Sambuc c->require_preauth = TRUE;
54ebfedea0SLionel Sambuc c->kdc_warn_pwexpire = 0;
55ebfedea0SLionel Sambuc c->encode_as_rep_as_tgs_rep = FALSE;
56*0a6a1f1dSLionel Sambuc c->tgt_use_strongest_session_key = FALSE;
57*0a6a1f1dSLionel Sambuc c->preauth_use_strongest_session_key = FALSE;
58*0a6a1f1dSLionel Sambuc c->svc_use_strongest_session_key = FALSE;
59*0a6a1f1dSLionel Sambuc c->use_strongest_server_key = TRUE;
60ebfedea0SLionel Sambuc c->check_ticket_addresses = TRUE;
61ebfedea0SLionel Sambuc c->allow_null_ticket_addresses = TRUE;
62ebfedea0SLionel Sambuc c->allow_anonymous = FALSE;
63ebfedea0SLionel Sambuc c->trpolicy = TRPOLICY_ALWAYS_CHECK;
64ebfedea0SLionel Sambuc c->enable_pkinit = FALSE;
65ebfedea0SLionel Sambuc c->pkinit_princ_in_cert = TRUE;
66ebfedea0SLionel Sambuc c->pkinit_require_binding = TRUE;
67ebfedea0SLionel Sambuc c->db = NULL;
68ebfedea0SLionel Sambuc c->num_db = 0;
69ebfedea0SLionel Sambuc c->logf = NULL;
70ebfedea0SLionel Sambuc
71ebfedea0SLionel Sambuc c->require_preauth =
72ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
73ebfedea0SLionel Sambuc c->require_preauth,
74ebfedea0SLionel Sambuc "kdc", "require-preauth", NULL);
75ebfedea0SLionel Sambuc #ifdef DIGEST
76ebfedea0SLionel Sambuc c->enable_digest =
77ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
78ebfedea0SLionel Sambuc FALSE,
79ebfedea0SLionel Sambuc "kdc", "enable-digest", NULL);
80ebfedea0SLionel Sambuc
81ebfedea0SLionel Sambuc {
82ebfedea0SLionel Sambuc const char *digests;
83ebfedea0SLionel Sambuc
84ebfedea0SLionel Sambuc digests = krb5_config_get_string(context, NULL,
85ebfedea0SLionel Sambuc "kdc",
86ebfedea0SLionel Sambuc "digests_allowed", NULL);
87ebfedea0SLionel Sambuc if (digests == NULL)
88ebfedea0SLionel Sambuc digests = "ntlm-v2";
89ebfedea0SLionel Sambuc c->digests_allowed = parse_flags(digests,_kdc_digestunits, 0);
90ebfedea0SLionel Sambuc if (c->digests_allowed == -1) {
91ebfedea0SLionel Sambuc kdc_log(context, c, 0,
92ebfedea0SLionel Sambuc "unparsable digest units (%s), turning off digest",
93ebfedea0SLionel Sambuc digests);
94ebfedea0SLionel Sambuc c->enable_digest = 0;
95ebfedea0SLionel Sambuc } else if (c->digests_allowed == 0) {
96ebfedea0SLionel Sambuc kdc_log(context, c, 0,
97ebfedea0SLionel Sambuc "no digest enable, turning digest off",
98ebfedea0SLionel Sambuc digests);
99ebfedea0SLionel Sambuc c->enable_digest = 0;
100ebfedea0SLionel Sambuc }
101ebfedea0SLionel Sambuc }
102ebfedea0SLionel Sambuc #endif
103ebfedea0SLionel Sambuc
104ebfedea0SLionel Sambuc #ifdef KX509
105ebfedea0SLionel Sambuc c->enable_kx509 =
106ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
107ebfedea0SLionel Sambuc FALSE,
108ebfedea0SLionel Sambuc "kdc", "enable-kx509", NULL);
109ebfedea0SLionel Sambuc
110ebfedea0SLionel Sambuc if (c->enable_kx509) {
111ebfedea0SLionel Sambuc c->kx509_template =
112ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
113ebfedea0SLionel Sambuc "kdc", "kx509_template", NULL);
114ebfedea0SLionel Sambuc c->kx509_ca =
115ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
116ebfedea0SLionel Sambuc "kdc", "kx509_ca", NULL);
117ebfedea0SLionel Sambuc if (c->kx509_ca == NULL || c->kx509_template == NULL) {
118ebfedea0SLionel Sambuc kdc_log(context, c, 0,
119ebfedea0SLionel Sambuc "missing kx509 configuration, turning off");
120ebfedea0SLionel Sambuc c->enable_kx509 = FALSE;
121ebfedea0SLionel Sambuc }
122ebfedea0SLionel Sambuc }
123ebfedea0SLionel Sambuc #endif
124ebfedea0SLionel Sambuc
125*0a6a1f1dSLionel Sambuc c->tgt_use_strongest_session_key =
126*0a6a1f1dSLionel Sambuc krb5_config_get_bool_default(context, NULL,
127*0a6a1f1dSLionel Sambuc c->tgt_use_strongest_session_key,
128*0a6a1f1dSLionel Sambuc "kdc",
129*0a6a1f1dSLionel Sambuc "tgt-use-strongest-session-key", NULL);
130*0a6a1f1dSLionel Sambuc c->preauth_use_strongest_session_key =
131*0a6a1f1dSLionel Sambuc krb5_config_get_bool_default(context, NULL,
132*0a6a1f1dSLionel Sambuc c->preauth_use_strongest_session_key,
133*0a6a1f1dSLionel Sambuc "kdc",
134*0a6a1f1dSLionel Sambuc "preauth-use-strongest-session-key", NULL);
135*0a6a1f1dSLionel Sambuc c->svc_use_strongest_session_key =
136*0a6a1f1dSLionel Sambuc krb5_config_get_bool_default(context, NULL,
137*0a6a1f1dSLionel Sambuc c->svc_use_strongest_session_key,
138*0a6a1f1dSLionel Sambuc "kdc",
139*0a6a1f1dSLionel Sambuc "svc-use-strongest-session-key", NULL);
140*0a6a1f1dSLionel Sambuc c->use_strongest_server_key =
141*0a6a1f1dSLionel Sambuc krb5_config_get_bool_default(context, NULL,
142*0a6a1f1dSLionel Sambuc c->use_strongest_server_key,
143*0a6a1f1dSLionel Sambuc "kdc",
144*0a6a1f1dSLionel Sambuc "use-strongest-server-key", NULL);
145*0a6a1f1dSLionel Sambuc
146ebfedea0SLionel Sambuc c->check_ticket_addresses =
147ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
148ebfedea0SLionel Sambuc c->check_ticket_addresses,
149ebfedea0SLionel Sambuc "kdc",
150ebfedea0SLionel Sambuc "check-ticket-addresses", NULL);
151ebfedea0SLionel Sambuc c->allow_null_ticket_addresses =
152ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
153ebfedea0SLionel Sambuc c->allow_null_ticket_addresses,
154ebfedea0SLionel Sambuc "kdc",
155ebfedea0SLionel Sambuc "allow-null-ticket-addresses", NULL);
156ebfedea0SLionel Sambuc
157ebfedea0SLionel Sambuc c->allow_anonymous =
158ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
159ebfedea0SLionel Sambuc c->allow_anonymous,
160ebfedea0SLionel Sambuc "kdc",
161ebfedea0SLionel Sambuc "allow-anonymous", NULL);
162ebfedea0SLionel Sambuc
163ebfedea0SLionel Sambuc c->max_datagram_reply_length =
164ebfedea0SLionel Sambuc krb5_config_get_int_default(context,
165ebfedea0SLionel Sambuc NULL,
166ebfedea0SLionel Sambuc 1400,
167ebfedea0SLionel Sambuc "kdc",
168ebfedea0SLionel Sambuc "max-kdc-datagram-reply-length",
169ebfedea0SLionel Sambuc NULL);
170ebfedea0SLionel Sambuc
171ebfedea0SLionel Sambuc {
172ebfedea0SLionel Sambuc const char *trpolicy_str;
173ebfedea0SLionel Sambuc
174ebfedea0SLionel Sambuc trpolicy_str =
175ebfedea0SLionel Sambuc krb5_config_get_string_default(context, NULL, "DEFAULT", "kdc",
176ebfedea0SLionel Sambuc "transited-policy", NULL);
177ebfedea0SLionel Sambuc if(strcasecmp(trpolicy_str, "always-check") == 0) {
178ebfedea0SLionel Sambuc c->trpolicy = TRPOLICY_ALWAYS_CHECK;
179ebfedea0SLionel Sambuc } else if(strcasecmp(trpolicy_str, "allow-per-principal") == 0) {
180ebfedea0SLionel Sambuc c->trpolicy = TRPOLICY_ALLOW_PER_PRINCIPAL;
181ebfedea0SLionel Sambuc } else if(strcasecmp(trpolicy_str, "always-honour-request") == 0) {
182ebfedea0SLionel Sambuc c->trpolicy = TRPOLICY_ALWAYS_HONOUR_REQUEST;
183ebfedea0SLionel Sambuc } else if(strcasecmp(trpolicy_str, "DEFAULT") == 0) {
184ebfedea0SLionel Sambuc /* default */
185ebfedea0SLionel Sambuc } else {
186ebfedea0SLionel Sambuc kdc_log(context, c, 0,
187ebfedea0SLionel Sambuc "unknown transited-policy: %s, "
188ebfedea0SLionel Sambuc "reverting to default (always-check)",
189ebfedea0SLionel Sambuc trpolicy_str);
190ebfedea0SLionel Sambuc }
191ebfedea0SLionel Sambuc }
192ebfedea0SLionel Sambuc
193ebfedea0SLionel Sambuc c->encode_as_rep_as_tgs_rep =
194ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
195ebfedea0SLionel Sambuc c->encode_as_rep_as_tgs_rep,
196ebfedea0SLionel Sambuc "kdc",
197ebfedea0SLionel Sambuc "encode_as_rep_as_tgs_rep", NULL);
198ebfedea0SLionel Sambuc
199ebfedea0SLionel Sambuc c->kdc_warn_pwexpire =
200ebfedea0SLionel Sambuc krb5_config_get_time_default (context, NULL,
201ebfedea0SLionel Sambuc c->kdc_warn_pwexpire,
202ebfedea0SLionel Sambuc "kdc", "kdc_warn_pwexpire", NULL);
203ebfedea0SLionel Sambuc
204ebfedea0SLionel Sambuc
205ebfedea0SLionel Sambuc c->enable_pkinit =
206ebfedea0SLionel Sambuc krb5_config_get_bool_default(context,
207ebfedea0SLionel Sambuc NULL,
208ebfedea0SLionel Sambuc c->enable_pkinit,
209ebfedea0SLionel Sambuc "kdc",
210ebfedea0SLionel Sambuc "enable-pkinit",
211ebfedea0SLionel Sambuc NULL);
212ebfedea0SLionel Sambuc
213ebfedea0SLionel Sambuc
214ebfedea0SLionel Sambuc c->pkinit_kdc_identity =
215ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
216ebfedea0SLionel Sambuc "kdc", "pkinit_identity", NULL);
217ebfedea0SLionel Sambuc c->pkinit_kdc_anchors =
218ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
219ebfedea0SLionel Sambuc "kdc", "pkinit_anchors", NULL);
220ebfedea0SLionel Sambuc c->pkinit_kdc_cert_pool =
221ebfedea0SLionel Sambuc krb5_config_get_strings(context, NULL,
222ebfedea0SLionel Sambuc "kdc", "pkinit_pool", NULL);
223ebfedea0SLionel Sambuc c->pkinit_kdc_revoke =
224ebfedea0SLionel Sambuc krb5_config_get_strings(context, NULL,
225ebfedea0SLionel Sambuc "kdc", "pkinit_revoke", NULL);
226ebfedea0SLionel Sambuc c->pkinit_kdc_ocsp_file =
227ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
228ebfedea0SLionel Sambuc "kdc", "pkinit_kdc_ocsp", NULL);
229ebfedea0SLionel Sambuc c->pkinit_kdc_friendly_name =
230ebfedea0SLionel Sambuc krb5_config_get_string(context, NULL,
231ebfedea0SLionel Sambuc "kdc", "pkinit_kdc_friendly_name", NULL);
232ebfedea0SLionel Sambuc c->pkinit_princ_in_cert =
233ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
234ebfedea0SLionel Sambuc c->pkinit_princ_in_cert,
235ebfedea0SLionel Sambuc "kdc",
236ebfedea0SLionel Sambuc "pkinit_principal_in_certificate",
237ebfedea0SLionel Sambuc NULL);
238ebfedea0SLionel Sambuc c->pkinit_require_binding =
239ebfedea0SLionel Sambuc krb5_config_get_bool_default(context, NULL,
240ebfedea0SLionel Sambuc c->pkinit_require_binding,
241ebfedea0SLionel Sambuc "kdc",
242ebfedea0SLionel Sambuc "pkinit_win2k_require_binding",
243ebfedea0SLionel Sambuc NULL);
244ebfedea0SLionel Sambuc c->pkinit_dh_min_bits =
245ebfedea0SLionel Sambuc krb5_config_get_int_default(context, NULL,
246ebfedea0SLionel Sambuc 0,
247ebfedea0SLionel Sambuc "kdc", "pkinit_dh_min_bits", NULL);
248ebfedea0SLionel Sambuc
249ebfedea0SLionel Sambuc *config = c;
250ebfedea0SLionel Sambuc
251ebfedea0SLionel Sambuc return 0;
252ebfedea0SLionel Sambuc }
253ebfedea0SLionel Sambuc
254ebfedea0SLionel Sambuc krb5_error_code
krb5_kdc_pkinit_config(krb5_context context,krb5_kdc_configuration * config)255ebfedea0SLionel Sambuc krb5_kdc_pkinit_config(krb5_context context, krb5_kdc_configuration *config)
256ebfedea0SLionel Sambuc {
257ebfedea0SLionel Sambuc #ifdef PKINIT
258ebfedea0SLionel Sambuc #ifdef __APPLE__
259ebfedea0SLionel Sambuc config->enable_pkinit = 1;
260ebfedea0SLionel Sambuc
261ebfedea0SLionel Sambuc if (config->pkinit_kdc_identity == NULL) {
262ebfedea0SLionel Sambuc if (config->pkinit_kdc_friendly_name == NULL)
263ebfedea0SLionel Sambuc config->pkinit_kdc_friendly_name =
264ebfedea0SLionel Sambuc strdup("O=System Identity,CN=com.apple.kerberos.kdc");
265ebfedea0SLionel Sambuc config->pkinit_kdc_identity = strdup("KEYCHAIN:");
266ebfedea0SLionel Sambuc }
267ebfedea0SLionel Sambuc if (config->pkinit_kdc_anchors == NULL)
268ebfedea0SLionel Sambuc config->pkinit_kdc_anchors = strdup("KEYCHAIN:");
269ebfedea0SLionel Sambuc
270ebfedea0SLionel Sambuc #endif /* __APPLE__ */
271ebfedea0SLionel Sambuc
272ebfedea0SLionel Sambuc if (config->enable_pkinit) {
273ebfedea0SLionel Sambuc if (config->pkinit_kdc_identity == NULL)
274ebfedea0SLionel Sambuc krb5_errx(context, 1, "pkinit enabled but no identity");
275ebfedea0SLionel Sambuc
276ebfedea0SLionel Sambuc if (config->pkinit_kdc_anchors == NULL)
277ebfedea0SLionel Sambuc krb5_errx(context, 1, "pkinit enabled but no X509 anchors");
278ebfedea0SLionel Sambuc
279ebfedea0SLionel Sambuc krb5_kdc_pk_initialize(context, config,
280ebfedea0SLionel Sambuc config->pkinit_kdc_identity,
281ebfedea0SLionel Sambuc config->pkinit_kdc_anchors,
282ebfedea0SLionel Sambuc config->pkinit_kdc_cert_pool,
283ebfedea0SLionel Sambuc config->pkinit_kdc_revoke);
284ebfedea0SLionel Sambuc
285ebfedea0SLionel Sambuc }
286ebfedea0SLionel Sambuc
287ebfedea0SLionel Sambuc return 0;
288ebfedea0SLionel Sambuc #endif /* PKINIT */
289ebfedea0SLionel Sambuc }
290