tsigconf.c revision f44202ab640d22e17b4c74bdad7817622918bd27
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999-2001, 2004-2007, 2009, 2011, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * This Source Code Form is subject to the terms of the Mozilla Public
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * License, v. 2.0. If a copy of the MPL was not distributed with this
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * file, You can obtain one at http://mozilla.org/MPL/2.0/.
15a44745412679c30a6d022733925af70a38b715David Lawrence/* $Id: tsigconf.c,v 1.35 2011/01/11 23:47:12 tbox Exp $ */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonadd_initial_keys(const cfg_obj_t *list, dns_tsig_keyring_t *ring,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson keyid = cfg_obj_asstring(cfg_map_getname(key));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson (void)cfg_map_get(key, "algorithm", &algobj);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson (void)cfg_map_get(key, "secret", &secretobj);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(algobj != NULL && secretobj != NULL);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Create the key name.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_constinit(&keynamesrc, keyid, strlen(keyid));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_add(&keynamesrc, strlen(keyid));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&keynamebuf, keynamedata, sizeof(keynamedata));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_name_fromtext(&keyname, &keynamesrc, dns_rootname,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Create the algorithm.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (ns_config_getkeyalgorithm(algstr, &alg, &bits)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson cfg_obj_log(algobj, ns_g_lctx, ISC_LOG_ERROR,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson "key '%s': has a unsupported algorithm '%s'",
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson secretalloc = secretlen = strlen(secretstr) * 3 / 4;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&secretbuf, secret, secretlen);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = isc_base64_decodestring(secretstr, &secretbuf);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence secretlen = isc_buffer_usedlength(&secretbuf);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ret = dns_tsigkey_create(&keyname, alg, secret, secretlen,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Set digest bits.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson cfg_obj_log(key, ns_g_lctx, ISC_LOG_ERROR,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonns_tsigkeyring_fromconfig(const cfg_obj_t *config, const cfg_obj_t *vconfig,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_mem_t *mctx, dns_tsig_keyring_t **ringp)
19f4d25fd5b35b1375b0b9f13b66770ee4a66154Brian Wellington maps[i++] = cfg_tuple_get(vconfig, "options");
19f4d25fd5b35b1375b0b9f13b66770ee4a66154Brian Wellington result = dns_tsigkeyring_create(mctx, &ring);
7bf91d95eb5a49117d5080bbd03839b9de5c8423Andreas Gustafsson for (i = 0; ; i++) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = cfg_map_get(maps[i], "key", &keylist);